How to sort a List in Descending order
In this article, I will be demonstrating how you can sort a List in descending order. In order to see how to sort a List, you can refer to this blog post. Approach 1 – Using Collections.reverse The Collections class has a utility method called reverse. You can use this to sort a List in descending order. The following code demonstrates this: private static void usingCollectionsReverse() { List<Integer> input = Arrays.asList(15,12,34,11,93,21,64); System.out.println("Before sorting:"+input); Collections.sort(input); Collections.reverse(input); System.out.println("After sorting:"+input);} Here, the code first invokes the Collection.sort . This sorts the List in ascending order. Then the code invokes the Collections.reverse method to reverse the List. So this code prints the following output: Before sorting:[15, 12, 34, 11, 93, 21, 64]After sorting:[93, 64, 34, 21, 15, 12, 11] Approach 2 – Using Collections.reverseOrder There is an overloaded version of ...