Tamara Tamara - 1 year ago 79
Java Question

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

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

Answer Source

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());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download