- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
java.util.Collections.reverseOrder() Method
Description
The reverseOrder(Comparator<T>) method is used to get a comparator that imposes the reverse ordering of the specified comparator.
Declaration
Following is the declaration for java.util.Collections.reverseOrder() method.
public static <T> Comparator<T> reverseOrder(Comparator<T> cmp)
Parameters
cmp − This is the comparator.
Return Value
The method call returns a comparator that imposes the reverse ordering of the specified comparator.
Exception
NA
Example
The following example shows the usage of java.util.Collections.reverseOrder()
package com.tutorialspoint;
import java.util.*;
public class CollectionsDemo {
public static void main(String args[]) {
// create linked list object
LinkedList<Integer> list = new LinkedList<Integer>();
// populate the list
list.add(-28);
list.add(20);
list.add(-12);
list.add(8);
// create comparator for reverse order
Comparator<Integer> cmp = Collections.reverseOrder(null);
// sort the list
Collections.sort(list, cmp);
System.out.println("List sorted in ReverseOrder: ");
for(int i : list) {
System.out.println(i+ " ");
}
}
}
Let us compile and run the above program, this will produce the following result.
List sorted in ReverseOrder: 20 8 -12 -28
java_util_collections.htm
Advertisements