stream流分組排序收集
阿新 • • 發佈:2022-12-06
1、根據屬性中包含有”離職"排序,並返回物件集合
tempList.stream().sorted(Comparator.comparing((SimpleUserVO s) -> s.getUserName().contains("離職"))).collect(Collectors.toList());
2、根據屬性分組,並且分組中取最大id的物件,返回map
SupplierList.stream().collect(groupingBy(lxwarehouse -> String.valueOf(lxwarehouse.getSupplierId()), LinkedHashMap::new, Collectors.collectingAndThen(Collectors.maxBy(Comparator.comparingInt(PdinfoSupplier::getId)), Optional::get)));
3、根據多個屬性分組,返回map
warehouseList.stream().collect(groupingBy(lxwarehouse -> lxwarehouse.getType() + "_" + lxwarehouse.getAccount(), LinkedHashMap::new, toList()))
4、取屬性中一部分組裝成LIST集合
listingsTemp.stream().map(listing -> StrUtil.split(listing.getAccount(), '-').get(1)).collect(Collectors.toList());
5、陣列轉LIST集合
StrUtil.split(strategyDaysStr, ',').stream().map(strategyDay -> Integer.parseInt(strategyDay)).collect(Collectors.toList());