Sorting a collection is done using the Collections.sort(Collection) to sort your values. This method is for those who implements Comparable interface. This interface defines the method compare which performs pairwise comparison of the elements and returns -1 if the element is smaller then the compared element, 0 if it is equal and 1 if it is larger. A Common example is Integer class.
If what to sort differently you can define your own implementation based on the Comparatorinterface.This approach is that you then sort any object by any attribute or even a combination of attributes. For example if you have objects of type Person with an attribute income and dateOfBirth you could define different implementations of Comparator and sort the objects according to your needs.