1.根据对象的某个属性去重: 网上找的stream流去重方法,可以根据类的某个属性去重,这里记录一下 public static Predicate distinctNotByKey(Function keyExtract
1.根据对象的某个属性去重:
网上找的stream流去重方法,可以根据类的某个属性去重,这里记录一下
public static Predicate distinctNotByKey(Function super T, ?> keyExtractor) { Map
使用:
public static void testC() { List list = new ArrayList<>(); UserAccount a = new UserAccount(); a.setId(57L); UserAccount b = new UserAccount(); b.setId(57L); UserAccount c = new UserAccount(); c.setId(56L); list.add(a); list.add(b); list.add(c); //根据id去重 List collect = list.stream().filter(distinctByKey(UserAccount::getId)).collect(Collectors.toList()); System.out.println(collect); System.out.println(collect.size()); }
来源地址:https://blog.csdn.net/weixin_38860401/article/details/131447130
--结束END--
本文标题: java Stream去重操作
本文链接: https://www.lsjlt.com/news/389413.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-03
2024-04-03
2024-04-01
2024-01-21
2024-01-21
2024-01-21
2024-01-21
2023-12-23
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0