Nice! But if you’re into Java Streams, here’s an even more functional approach. You can use Streams to sort the list in descending order like this:
List<Double> sortedList = testList.stream()
.sorted(Comparator.reverseOrder())
.toList(); // toList() is available from Java 16+
System.out.println(sortedList);
This method is particularly helpful if you’re already working with Streams in your code. It’s not just about sorting but also chaining other operations in a fluent, readable way. Performance-wise, for large lists, Streams can sometimes have a slight overhead due to internal operations, but it’s still a highly efficient way of working with collections, especially if you’re familiar with functional programming. So, java sort list via Streams might be your best bet if you’re into that functional style!