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
For your example, this will do the magic in Java 8
List testList = new ArrayList();
testList.sort(Comparator.naturalOrder());
But if you want to sort by some of the fields of the object you are sorting, you can do it easily by:
testList.sort(Comparator.comparing(ClassName::getFieldName));
or
testList.sort(Comparator.comparing(ClassName::getFieldName).reversed());
or
testList.stream().sorted(Comparator.comparing(ClassName::getFieldName).reversed()).collect(Collectors.toList());
Sources: https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html