List<String> approvalObjectList=["1,2","3,4"]
目标
List<Long> approvalObjectIdList=[1,2,3,4]
第一种方式
List<Long> toBeApprovedIdList=new ArrayList<>();
for(String approvalObject:approvalObjectList){
if(StringUtils.isNotBlank(approvalObject)){
toBeApprovedIdList.addAll(
Arrays.stream(approvalObject.split(","))
.map(Long::valueOf).collect(Collectors.toList())
);
}
}
第二种方式
List<Long> toBeApprovedIdList = approvalObjectList.stream()
.flatMap(r -> Arrays.stream(r.split(",")))
.map(Long::valueOf)
.collect(Collectors.toList());