You should implement the Comparator
interface.
example:
public class CustomComparator implements Comparator<CustomObject>
{
@Override
public int compare(CustomObject o1, CustomObject o2) {
return o1.getId().compareTo(o2.getId());
}
}
Then you can use the Collections classes Collections.sort()
method:
Collections.sort(list, new CustomComparator());