我试图对此进行排序 ArrayList<Person>
以相反的顺序,但这不会编译
List<Person> newList = arrayList.stream()
.sorted(Comparator.reverseOrder(Person::getAge)) //Error
.limit(3)
.collect(Collectors.toList());
newList.forEach(System.out::println);
还有其他方法可以对流进行相反的排序吗?
最佳答案
正确的使用方法如下:
.sorted(Comparator.comparing(Person::getAge).reversed())
关于java - 为什么我不能在这段代码中以相反的顺序排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57095585/