Java: ArrayList Sort

To use Java's Collections sort methods, the class of objects that need to be sorted must implement Comparable in the class you need to sort.  By adding implements Comparable in the class header, it will force the class to contain a compareTo( ) method.  Notice that the parameter is of type Object and the object must be caste to the User class in the compareTo() method

The Collection.sort( ) method can be used to sort any of objects that implement Comparable. 


Comments