Collections - Sorting ArrayList of user-defined objects

How do you sort an ArrayList (or any list) of user-defined objects ?

Create an implementation of the java.lang.Comparable interface that knows how to order your objects and pass it to java.util.Collections.sort(List, Comparator). If we use Collections.sort(arraylist), the elements in the arraylist will be sorted by natural order.

See Comparator interface vs Comparable interface


Links to this note