当前位置:网站首页>对象集合去重的方法
对象集合去重的方法
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());
}
边栏推荐
猜你喜欢

HCIP第十五天笔记
How to ensure the consistency of database and cache data?

Oracle一个诡异的临时表空间不足的问题

Word文件损坏如何修复

45.【list链表的应用】

HCIP第十六天笔记

2022 China Logistics Industry Conference and Entrepreneur Summit Forum will be held in Hangzhou!

Steven Giesel recently published a 5-part series documenting his first experience building an application with the Uno Platform.

JS中? ?和??=和?.和 ||的区别

.NET Cross-Platform Application Development Hands-on Tutorial | Build a Kanban-style Todo App with Uno Platform
随机推荐
joiplay模拟器rtp如何安装
Ukraine's foreign ministry: wu was restored to complete the export of food security
oracle数据库版本问题咨询(就是对比从数据库查询出来的版本,和docker里面的oracle版本)?
joiplay模拟器报错如何解决
10 个关于自动化发布管理的好处
动态修改el-tab-pane 的label(整理)
Game mall table establishment
$\text{ARC 145}$
[0x800706D9] solution appears in Microsoft Store
leetcode 406. Queue Reconstruction by Height 根据身高重建队列(中等)
状态机动态规划之股票问题总结
封装、获取系统用户信息、角色及权限控制
[Meng Xin problem solving] Delete the Nth node from the bottom of the linked list
牛逼的公司都在用的绩效管理法OKR
How to ensure the consistency of database and cache data?
Android安全性优化——APP加固
"Wei cup" school more than 2022 cattle summer camp 4 L.B lack Hole, computational geometry
What are the efficient open source artifacts of VSCode
【LeetCode】64. 最小路径和 - Go 语言题解
Summary of the stock problem of state machine dynamic programming