Tamara Tamara - 5 months ago 12
Java Question

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

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


Here's one way for your list:


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

Collections.sort(list, new Comparator<Long>() {
    public int compare(Long o1, Long o2) {
        return o2.compareTo(o1);

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

Collections.sort(list, Collections.reverseOrder());