With Eclipse Collections you could create a primitive double list, sort it and then reverse it to put it in descending order. This approach would avoid boxing the doubles.
MutableDoubleList doubleList =
DoubleLists.mutable.with(
0.5, 0.2, 0.9, 0.1, 0.1, 0.1, 0.54, 0.71,
0.71, 0.71, 0.92, 0.12, 0.65, 0.34, 0.62)
.sortThis().reverseThis();
doubleList.each(System.out::println);
If you want a List<Double>
, then the following would work.
List<Double> objectList =
Lists.mutable.with(
0.5, 0.2, 0.9, 0.1, 0.1, 0.1, 0.54, 0.71,
0.71, 0.71, 0.92, 0.12, 0.65, 0.34, 0.62)
.sortThis(Collections.reverseOrder());
objectList.forEach(System.out::println);
If you want to keep the type as ArrayList<Double>
, you can initialize and sort the list using the ArrayListIterate
utility class as follows:
ArrayList<Double> arrayList =
ArrayListIterate.sortThis(
new ArrayList<>(objectList), Collections.reverseOrder());
arrayList.forEach(System.out::println);
Note: I am a committer for Eclipse Collections.