【发布时间】:2020-04-05 11:17:48
【问题描述】:
我们有一个Map<String, Student> studentMap,其中Student 是一个类,如下所示:
class Student{
String name;
int age;
}
我们需要返回一个包含所有 ID eligibleStudents 的列表,其中年龄 > 20。
为什么在Collectors.toList下面会出现编译错误:
HashMap<String, Student> studentMap = getStudentMap();
eligibleStudents = studentMap .entrySet().stream()
.filter(a -> a.getValue().getAge() > 20)
.collect(Collectors.toList(Entry::getKey));
【问题讨论】:
标签: java list dictionary java-8 java-stream