jdk 1.8 stream

发布时间 2024-01-11 18:42:17作者: 恃才傲物123

1.将集合中某字段抽取去重为集合

List<String> pillarsSidList = sdPillarsInstalls.stream().map(SdPillarsInstall::getPillarsSid).distinct().collect(Collectors.toList());

2.将集合中某字段提取为MAP

Map<Long, NyNybtPurchaseInfoReport> purchaseOrderIdMap = purchaseOrderList.stream().collect(Collectors.toMap(NyNybtPurchaseInfoReport::getId, Function.identity()));

3.将集合中某字段提取为集合

List<String> detailIdList = childrenList.stream().map(NyNybtSubsidyGatherReportDetail::getDetailIds).collect(Collectors.toList());

4.将集合中某字段提取进行拼接成字符串

String orderNumberStr = purchaseOrderRepeatList.stream().map(NyNybtPurchaseInfoReport::getOrderNumber).collect(Collectors.joining(","));

5.将集合中某字段提取为MAP<String,List>

Map<String, List<NyNybtPurchaseInfoReport>> map = purchaseOrderList.stream().collect(Collectors.groupingBy(NyNybtPurchaseInfoReport::getPurchaserSid));