I have a List of doubles in java and I want to sort ArrayList in descending order.
Input ArrayList is as below:
List testList = new Arr
With Java8 there is a default sort method on the List interface that will allow you to sort the collection if you provide a Comparator. You can easily sort the example in the question as follows:
testList.sort((a, b) -> Double.compare(b, a));
Note: the args in the lambda are swapped when passed in to Double.compare to ensure the sort is descending