java.util.Collections.reverseOrder() method is a java.util.Collections class method.
// Returns a comparator that imposes the reverse of // the natural ordering on a collection of objects // that implement the Comparable interface. // The natural ordering is the ordering imposed by // the objects' own compareTo method public static Comparator reverseOrder()
We can the comparator returned by Collections.reverseOrder() to sort a list in descending order.
List after the use of Collection.reverseOrder() and Collections.sort(): [50, 40, 30, 20, 10]
We can use this method with Arrays.sort() also.
Array after the use of Collection.reverseOrder() and Arrays.sort() : [40, 30, 20, 10]
It returns a Comparator that imposes reverse order of a passed Comparator object. We can use this method to sort a list in reverse order of user defined Comparator. For example, in the below program, we have created a reverse of user defined comparator to sort students in descending order of roll numbers.
Unsorted 111 bbbb london 131 aaaa nyc 121 cccc jaipur Sorted by rollno 131 aaaa nyc 121 cccc jaipur 111 bbbb london
This article is contributed by Mohit Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java Clock tickMinutes() method in Java with Examples
- Java Clock withZone() method in Java with Examples
- Java.util.Arrays.equals() in Java with Examples
- Java 8 | ArrayDeque removeIf() method in Java with Examples
- Java.util.Collections.frequency() in Java with Examples