-2
If Collections.sort(lista);
sort the list ascendingly, which command can I use to leave a list in descending order?
-2
If Collections.sort(lista);
sort the list ascendingly, which command can I use to leave a list in descending order?
3
There is an overload of the method Collections.sort()
which takes as the second parameter an object Comparator
(documentation), and the class itself Collections
has another method that returns just one comparator object that imposes a reverse order on the list, the Collections.reverseOrder()
(documentation).
The code goes like this:
Collections.sort(lista, Collections.reverseOrder());
Browser other questions tagged java
You are not signed in. Login or sign up in order to post.
Present a [mcve] of your code so that it is possible to suggest something based on what you have done, and so that the question does not look like a code request ready, which is not welcome here.
– user28595
@Hexacampão articuno Actually I just needed to know what was the inverse of
Collections.sort(lista);
that I eventually discovered isCollections.reverse(teste);
but thank you for the reply.– aguiarito
Note that the method
Collections.reverse()
will not sort the list, as you suggest in the question, it just reverses the list order without ordering it.– Pedro Gaspar