List Stream用法实例

原创
2020/09/24 16:30
阅读数 178

 List<AttendanceReport> attendanceReports = attendanceConfigs.stream().parallel().map(
                operationAttendanceConfig -> {
                    String orgIdsStr = operationAttendanceConfig.getOrgIds();
                    AttendanceReport attendanceReport = buildAttdanceReport(orgIdsStr);
                    return attendanceReport;
                }
        ).filter(attendanceReport -> attendanceReport != null)
         .filter(attendanceReport -> attendanceReport.getIcon() != null)
         .filter(attendanceReport -> attendanceReport.getName() != null)
         .collect(Collectors.toList());

 

//List集合转成Map集合
//                Map<Integer, WorkShiftPeriodSnapshot> collect =
//                workShiftPeriodSnapshots.stream().collect(Collectors.toMap(WorkShiftPeriodSnapshot::getId, value -> value));

 

//List集合转成特定属性集合
List<Integer> flowList = approvalNode.stream().map(ApprovalNode::getFlowId).distinct().collect(Collectors.toList());

//特定分割字符串转List

List<Integer> idArray = Arrays.asList(customerIds.split(",")).stream().map(Integer::valueOf).collect(Collectors.toList());

//数组对象集合极细

MapAreaDto[] mapAreaDtos1 = JSONObject.parseObject(workSchedule.getMapAreaIds(), new TypeReference<MapAreaDto[]>() {});
List<String>  list = Arrays.stream(mapAreaDtos1).map(mapAreaDto -> mapAreaDto.getMapAreaName()).distinct().collect(Collectors.toList());

 

### 将数组拼接字符串

String mapAreaNames = mapAreaDtos.stream().map(mapAreaDto -> mapAreaDto.getMapAreaName()).collect(Collectors.joining(","));

 

 

相关资料:

https://www.jianshu.com/p/0bb4daf6c800?from=groupmessage

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部