当前位置: 首页 > 后端技术 > Java

Collectors的映射和收集AndThen

时间:2023-04-02 10:16:52 Java

//对于Map的值,先将PutTarget转换为CoursePutApply,然后调用toList()Map>result1=this.putTargets.stream().collect(Collectors.groupingBy(PutTarget::getCity,Collectors.mapping((PutTargetputTarget)->newCoursePutApply(),toList())));//对于Map的值,先调用toList(),然后将PutTarget转换为CoursePutApplyMapresult2=this.putTargets.stream().collect(Collectors.groupingBy(PutTarget::getCity,Collectors.collectingAndThen(toList(),(Listlist)->newCoursePutApply(this.courseId,list))));