Sort List in reverse in order
Use this:
Collections.reverse(list);
There is a method reverseOrder
in the Collections
class which returns a Comparator
.
You can use it like Collections.sort(list, Collections.reverseOrder());
How I would do it is:
personsList.sort(Comparator.comparing(Person::getAge, Comparator.reverseOrder()));
And happy coding :)
you can reverse any type by just putting "-" or negative sign infront of your return.
Collections.sort(listed, new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
return -o1.getLeft().compareTo(o2.getLeft());
}
});