Collections.reverseOrder(Comparator <T> cmp) has the following syntax.
public static <T> Comparator <T> reverseOrder(Comparator <T> cmp)
In the following code shows how to use Collections.reverseOrder(Comparator <T> cmp) method.
import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; import java.util.List; //from w w w . ja va2s . c o m public class Main { public static void main(String args[]) { // create linked list object List<Integer> list = new LinkedList<Integer> (); // populate the list list.add(-2); list.add(2); list.add(-12); list.add(8); // create comparator for reverse order Comparator cmp = Collections.reverseOrder(Collections.reverseOrder()); // sort the list Collections.sort(list, cmp); System.out.println(list); } }
The code above generates the following result.