reverseOrder()
Java Collections reverseOrder() Method
Last Updated : 17 Mar 2025
The reverseOrder() is a Java Collections class method which returns a comparator that imposes the reverse of the natural ordering on the objects. There is two different types of Java reverseOrder() method which can be differentiated depending on its parameter. These are:
- Java Collections reverseOrder() Method
- Java Collections reverseOrder(comp) Method
Java Collections reverseOrder() Method
The reverseOrder() method of Java Collections class is used to get the comparator that imposes the reverse of the natural ordering on a collection of objects which implement the Comparable interface.
Java Collections reverseOrder(comp) Method
The reverseOrder() method of Java Collections class is used to get the comparator that imposes the reverse ordering of the specified comparator.
Syntax
Following is the declaration of reverseOrder() method:
Parameter
| Parameter | Description | Required/Optional |
|---|---|---|
| comp | It is a comparator whose ordering is to be reversed by the returned comparator or null. | Required |
Returns
| Method | Returns |
|---|---|
| reverseOrder() | It returns a comparator that imposes the reverse natural ordering on a collection of objects that implement the Comparable interface. |
| reverseOrder(Comparatorcomp) | It returns a comparator that imposes the reverse ordering of the specified comparator. |
Exceptions
NA
Compatibility Version
Java 1.5 and above
Example 1
Output:
List sorted in ReverseOrder: [90, 50, 10, -15, -20]
Example 2
Output:
List sorted in ReverseOrder: [Ruby, Python, Java, COBOL]
Example 3
Output:
[Ruby, Commit, Pratham, Jaya]
Example 4
Output:
List sorted in ReverseOrder: 120 50 -20 -80
Next TopicJava Collections Class