How to sort ArrayList<Long> in decreasing order?

java

Solution

Here's one way for your `list`:

list.sort(null);
Collections.reverse(list);

Or you could implement your own `Comparator` to sort on and eliminate the reverse step:

list.sort((o1, o2) -> o2.compareTo(o1));

Or even more simply use `Collections.reverseOrder()` since you're only reversing:

list.sort(Collections.reverseOrder());

Problem

How to sort an `ArrayList<Long>` in Java in decreasing order?

Original source