stream 过滤集合,按照行号排序,取mun最大值的数据
Map<String, IWLS_EnDepotEntry> collect = endepot.stream().collect( Collectors.groupingBy(IWLS_EnDepotEntry::getPurBCode, Collectors.collectingAndThen(Collectors.reducing((c1, c2) -> c1.getNum().intValue() > c2.getNum().intValue() ? c1 : c2), Optional::get))); endepot = new ArrayList<>(collect.values()); Map<String, IWLS_EnDepotEntry> collect1 = enDepotEntryList.stream().collect( Collectors.groupingBy(IWLS_EnDepotEntry::getPurBCode, Collectors.collectingAndThen(Collectors.reducing((c1, c2) -> c1.getNum().intValue() > c2.getNum().intValue() ? c1 : c2), Optional::get))); enDepotEntryList = new ArrayList<>(collect1.values());
先转换成流 ,接着使用 Collectors.groupingBy 进行分组,Collectors.collectingAndThen 分组后继续处理。

浙公网安备 33010602011771号