Comparator reverseOrder() method in Java with examples Last Updated : 12 Apr, 2023 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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: Program 1: Java // Java program to demonstrate // Comparator.reverseOrder() method import java.util.Arrays; import java.util.Comparator; import java.util.List; public class GFG { public static void main(String... args) { List<Integer> values = Arrays.asList(212, 324, 435, 566, 133, 100, 121); // reverseOrder is a static method values.sort(Comparator.reverseOrder()); // print sorted number based on reverse order System.out.println(values); } } The output printed on console of IDE is shown below. Output: Program 2: Java // Java program to demonstrate // Comparator.reverseOrder() method import java.util.Arrays; import java.util.Comparator; import java.util.List; public class GFG { public static void main(String... args) { List<String> stringList = Arrays.asList("Aman", "Kajal", "Joyita", "Das"); System.out.println("Before sorting:"); stringList.forEach(System.out::println); stringList.sort(Comparator.reverseOrder()); System.out.println("\nAfter sorting:"); stringList.forEach(System.out::println); } } The output printed on console is shown below. Output: References: https://docs.oracle.com/javase/10/docs/api/java/util/Comparator.html#reverseOrder() Comment More infoAdvertise with us Next Article Comparator reverseOrder() method in Java with examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-Comparator Practice Tags : Java Similar Reads Comparator reversed() method in Java with examples The reversed() method of Comparator Interface in Java returns a comparator that imposes the reverse ordering of this comparator. If you use sort method of the array and passes this comparator after applying the reversed method then it will sort the array in reverse order. Syntax: default Comparator 2 min read TreeSet comparator() Method in Java with Examples TreeSet is one of the most important implementations of the SortedSet interface in Java that uses a Tree for storage. The ordering of the elements is maintained by a set using their natural ordering whether or not an explicit comparator is provided. This must be consistent with equals if it is to co 3 min read Comparator naturalOrder() method in Java with examples The naturalOrder() method of Comparator Interface in Java returns a comparator that use to compare Comparable objects in natural order. The returned comparator by this method is serializable and throws NullPointerException when comparing null. Syntax: static <T extends Comparable<T>> Com 1 min read SortedMap comparator() method in Java with Examples The comparator() method of java.util.SortedMap interface is used to return the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.Syntax: public Comparator comparator() Return Value: This method returns the comparator used to order the keys in th 2 min read TreeMap comparator() method in Java with Examples The comparator() method of java.util.TreeMap class is used to return the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys. --> java.util Package --> TreeMap Class --> comparator() Method Syntax: public Comparator comparator() Return Ty 2 min read Like