Sorting List in Java

-2

If Collections.sort(lista); sorts the list incrementally, what command can I use to drop a list in descending order?

    
asked by anonymous 03.11.2018 / 04:00

1 answer

2

It has an overload of the Collections.sort() method that receives a Comparator object as its second parameter ( documentation ), and the Collections class itself has another method that returns a comparator object that imposes a reverse order on the list, Collections.reverseOrder() ( documentation ).

The code looks like this:

Collections.sort(lista, Collections.reverseOrder());
    
03.11.2018 / 05:10