Comparator reverseOrder() method in Java with examples
The reverseOrder() method of Comparator Interface in Java returns a comparator that use to compare Comparable objects in reverse of natural order. The returned comparator by this method is serializable and throws NullPointerException when comparing null.
static <T extends Comparable<T>> Comparator<T> reverseOrder()
Parameters: This method accepts nothing.
Return value: This method returns a comparator that imposes the reverse natural ordering on Comparable objects.
Below programs illustrate reverseOrder() method:
The output printed on console of IDE is shown below.
The output printed on console is shown below.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.