当前位置:网站首页>对象集合去重的方法
对象集合去重的方法
2022-07-31 00:00:00 【EntyIU】
有的时候我们有这样的需求,在一个集合中有几个对象的数据是重复的,我们只想取不重复的那几个,可以通过以下方法去做
//这里讲述的是通过tDeptId这个字段去重
private static <T> Predicate<T> distinctByVariable(Function<? super T, ?> keyExtractor){
HashMap<Object, Boolean> map = new HashMap<>();
return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
public HttpResult updateUserInfo(@RequestBody UpdateUserParam updateUserParam) {
List<UpdateDeptCheckParam> collect3 = collect.stream().filter(distinctByVariable(u -> u.getDeptId())).collect(Collectors.toList());
}
边栏推荐
猜你喜欢
随机推荐
.NET 跨平台应用开发动手教程 |用 Uno Platform 构建一个 Kanban-style Todo App
MPI简谈
常用的正则表达式
动态修改el-tab-pane 的label(整理)
flex-direction容器属性
Steven Giesel recently published a 5-part series documenting his first experience building an application with the Uno Platform.
How to use joiplay emulator
Shell programming conditional statement test command Integer value, string comparison Logical test File test
实验8(vlan实验)
Shell编程条件语句 test命令 整数值,字符串比较 逻辑测试 文件测试
MySQL面试题
45. [Application of list linked list]
Android安全性优化——APP加固
HashSet源码解析
Dry goods | 4 tips for MySQL performance optimization
Ukraine's foreign ministry: wu was restored to complete the export of food security
leetcode 406. Queue Reconstruction by Height
XSS相关知识
How to open the payment channel interface?
如何在WordPress网站上添加导航菜单