我正在尝试使用Lightweight-Stream-API来支持低于 API-24 的支持。它适用于升序,但如何降序sortBy()
。
List<Person> persons = Arrays.asList(
new Person("Bill", 30),
new Person("Ali", 25),
new Person("Apula", 40),
new Person("Calin", 18),
new Person("Adomin", 20),
new Person("Amkita", 35),
new Person("Della", 40)
);
List<Person> result = com.annimon.stream.Stream.of(persons)
.filter(x -> x.getName().startsWith("A"))
.sortBy(Person::getAge) // how to make it descending?
.limit(2)
.toList();