In this example we will show how to use java.util.Comparator interface. java.util.Comparator is an interface which is used for sorting objects in Java. The compare(Object o1, Object o2) method of Comparator interface needs to be implemented for this purpose, which compares two objects and returns an integer, depending on the comparison: positive, if o1 is greater than o2; zero, if o1 equals to o2; negative, if o1 is less than o1. Another interface which is used for sorting objects is java.lang.Comparable. However, Comparable cannot sort objects on different attributes, while Comparator can. Also, the method compareTo(T o) of Comparable needs to be implemented in this case, which compares the current object (this object) with the specified object for order. In this example, we will pay attention to Comparator interface.