javalistsortingguava

Sort List in reverse in order


I have List list1 in direct order. List<String> list = Ordering.natural().sortedCopy(asu2);

How to change order. And I don't know how to rewrite methods from extends class, please write with examples or speak clearly.


Solution

  • How I would do it is:

    personsList.sort(Comparator.comparing(Person::getAge, Comparator.reverseOrder()));
    

    And happy coding :)