So I have a class in java which I group variables together to create my object like so:
public class ExampleClass
{
private String name;
private String test;
private int etc;
public ExampleClass()
{
}
public String getName()
{
return name;
}
public void setName(String newName)
{
name = newName;
}
// ...
}
Then I create an array or list of these objects, but for this question we will say an array:
int counter = 10;
ExampleClass e[] = new ExampleClass[counter];
for(int i = 0; i < counter; i++)
{
ExampleClass e2 = ExampleClass();
e2.setName("a name"); // string grabbed from some other source...
// ...
e[i] = e2;
}
And then I fill the values with data which can be anything. Now my question is, how can I sort my array (or list) by alphabetical order of one of the variables, such as name? I've used Arrays.sort(theArray) before for when it's a String[] but I can't quite work out how to do this with my custom class.
Just to note, this is all in java for the Android but the platform shouldn't matter.