Assume I have a user defined Java class called Foo such as:
public class Foo { private String aField; @Override public String toString() {
Use the API sort(List list, Comparator c)which specifies a comparator, and implement is as you wish.
sort(List list, Comparator c)
Alternatively, if you do not specifically need a List, use a SortedSet, same goes with the comparator.