Reputation: 343
I was trying to sort this ArrayList<Person>
in a reverse order but this does not compile
List<Person> newList = arrayList.stream()
.sorted(Comparator.reverseOrder(Person::getAge)) //Error
.limit(3)
.collect(Collectors.toList());
newList.forEach(System.out::println);
Is there any other way to sort streams in a reverse order?
Upvotes: 0
Views: 106
Reputation: 3134
Here is the correct way to use it:
.sorted(Comparator.comparing(Person::getAge).reversed())
Upvotes: 5