stream流分组排序收集

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());

 6、排除不满足条件的对象

list = list.stream().filter(obj -> !StringUtils.isEmpty(obj.getFnsku())).collect(Collectors.toList());

 

posted @ 2022-12-06 17:21  卫GUO  阅读(672)  评论(0)    收藏  举报