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