Apr 192012
 

A shortcut to sorting some lists. Check out the API for more information. See below for examples in action.

LinkedList aList = new LinkedList<>();
aList.add(5);
aList.add(7);
aList.add(3);
aList.add(1);
aList.add(4);

// Not sorted
System.out.print(aList.toString()); // [5, 7, 3, 1, 4]

// Sort
Collections.sort(aList);

System.out.print(aList.toString()); // [1, 3, 4, 5, 7]

// And to reverse sort
Collections.sort(aList, Collections.reverseOrder()); 

System.out.print(aList.toString()); // [7, 5, 4, 3, 1]
 Posted by at 5:36 pm