【发布时间】:2018-02-04 14:47:14
【问题描述】:
有一个 Student 类,其中包含 name, surname, age 字段和 getter。
给定Student 对象流。
如何调用collect 方法,使其返回Map,其中键为Student 的age,值为TreeSet,其中包含surname 的学生age。
我想使用Collectors.toMap(),但卡住了。
我以为我可以这样做并将第三个参数传递给toMap方法:
stream().collect(Collectors.toMap(Student::getAge, Student::getSurname, new TreeSet<String>()))`.
【问题讨论】:
标签: java java-8 java-stream collectors