1.flatMap
将多个集合压平为一个集合
List<Long> siteIdList = routeLines.stream()
.flatMap(routeLine -> Stream.of(routeLine.getSubLineFSiteId(), routeLine.getSubLineTSiteId()))
.distinct()
.collect(Collectors.toList());
2. Collectors.toMap()
List<BaseWarehouse> warehouseList = ClientUtil.request(() -> vwmsClient.batchQueryWarehouse(new BaseWarehouseQueryForm()));
Map<String, BaseWarehouse> fenceNoWarehouseMap = warehouseList.stream()
.filter(w -> CollectionUtils.isNotEmpty(w.getFenceNoList()))
.flatMap(w -> w.getFenceNoList().stream().map(a -> new SimpleEntry<String, BaseWarehouse>(a, w)))
.collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue, (c, d) -> c));
标签:Collectors,flatMap,Stream,stream,示例,API,routeLine,SimpleEntry
From: https://www.cnblogs.com/IC1101/p/12486850.html