Stream 日常工作笔记
1.LIst 转Map
stream().collect(Collectors.toMap(SplaLineSnDTO::getId, Function.identity()))
2. List对象 先分组 在取其中一个字段 转List
stream().collect(Collectors.groupingBy(SplSnTransHistoryDTO::getInoutLineId, Collectors.mapping(SplSnTransHistoryDTO::getSplSnId, Collectors.toList())))
3. List对象先 分组 在求和
stream().collect(Collectors.groupingBy(OioLineDTO::getSourceLineId, Collectors.mapping(OioLineDTO::getQty, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
4.List对象 平铺 对象的属性
stream().flatMap(e -> e.getSnIds().stream()).collect(Collectors.toList());
5.List 对象去重
stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SoLineRespDTO::getGroupId))), ArrayList::new));