[Audio] Comparators. Comparators.
[Audio] What is comparator? Java comparator interface is used to order the objects of a user-defined class. This interface is found in java.util package and contains two methods compare with two object as parameter and equals method. Both TreeSet and TreeMap store elements in sorted order. These classes store their elements by natural ordering. If we want to order elements in a different way, then specify a comparator object when we construct the set or map..
[Audio] Here is the methods of Comparator. Methods.
[Audio] Other method. Methods. boolean equals(Object obj ) It checks whether an object obj is equal to the invoking comparator. This method returns true, if obj and the invoking object are both Comparator objects and use the same ordering. Otherwise it returns false..
[Audio] Here is a sample program using comparator.