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());
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了