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 @   卫GUO  阅读(642)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示