The idea is to use the custom
comparator, which should be some class implementing the interface
Comparable<T>
, where
T
should be the the type of the element of your list (or, possibly, the common base type of the
runtime types of the elements of the list, abstract or not). Please see:
http://docs.oracle.com/javase/6/docs/api/java/lang/Comparable.html[
^].
You will find some code sample here:
http://stackoverflow.com/questions/2784514/sort-arraylist-of-custom-objects-by-property[
^].
Now, this makes no sense and won't cast:
String[] names = (String[])members.toArray();
In your code, you should compare strings representing elements, not lists or arrays of elements. Instead, you should use
java.lang.Object.toString()
which you could override in your element class(es). Please see:
http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html[
^].
—SA