当前位置:网站首页>对象集合去重的方法
对象集合去重的方法
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());
}
边栏推荐
猜你喜欢
随机推荐
数据清洗-使用es的ingest
[动态规划] 0-1背包问题和完全背包问题
限制字符绕过
How to Repair Word File Corruption
Lambda表达式
xss靶机训练【实现弹窗即成功】
JS中? ?和??=和?.和 ||的区别
10 个关于自动化发布管理的好处
pytorch的安装注意事项
MySQL的一个问题
Chevrolet Trailblazer, the first choice for safety and warmth for your family travel
XSS相关知识
jira是什么
天空云变化案例
Shell编程条件语句 test命令 整数值,字符串比较 逻辑测试 文件测试
What are the efficient open source artifacts of VSCode
Unity 加载读取PPT
Oracle一个诡异的临时表空间不足的问题
Axure Carousel
牛逼的公司都在用的绩效管理法OKR