//对于Map的值,先把PutTarget转换为CoursePutApply,再调用toList()
Map<String, List<CoursePutApply>> result1 = this.putTargets.stream()
.collect(
Collectors.groupingBy(
PutTarget::getCity, Collectors.mapping((PutTarget putTarget) -> new CoursePutApply(), toList())
)
);
//对于Map的值,先调用toList(), 再把PutTarget转换为CoursePutApply
Map<String, CoursePutApply> result2 = this.putTargets.stream()
.collect(
Collectors.groupingBy(
PutTarget::getCity, Collectors.collectingAndThen(toList(), (List<PutTarget> list) -> newCoursePutApply(this.courseId, list))
)
);
Collectors的mapping和collectingAndThen
点赞
收藏