If Collections.sort(lista);
sorts the list incrementally, what command can I use to drop a list in descending order?
If Collections.sort(lista);
sorts the list incrementally, what command can I use to drop a list in descending order?
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());