当前位置:网站首页>The list set is de duplicated according to the object attributes
The list set is de duplicated according to the object attributes
2022-07-22 03:16:00 【haohaounique】
scene : according to list Some properties in the object ( Non empty ) duplicate removal , Keep unique values
Ideas : Make attributes unique keys , Then go heavy.
Example : Add an object repeatedly and test
import lombok.Data;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;
/**
* description:
*/
@Data
public class Org {
private String id;
private String pid;
public static void main(String[] args) {
List<Org> importList = new ArrayList<>();
Org org = new Org();
org.setId("001");
org.setPid("002");
Org org1 = new Org();
org1.setId("002");
org1.setPid("003");
Org org2 = new Org();
org2.setId("003");
org2.setPid("001");
importList.add(org);
importList.add(org);
importList.add(org1);
importList.add(org2);
ArrayList<Org> collect = importList.stream().collect(collectingAndThen(toCollection(() -> new TreeSet<>(Comparator.comparing(dto -> dto.getId() + dto.getPid()))), ArrayList::new));
System.out.println(collect);
}
}
边栏推荐
猜你喜欢
Introduction to MySQL user management and engine
Codeql usage process
Stream stream filters the list set for duplicate fields
SAP ABAP parsing function text of Excel file_ CONVERT_ XLS_ TO_ SAP single step analysis
Use of delete
[machine learning] hierarchical clustering
Elk+filebeat搭建分布式日志
大小端模式说明
网络数据包的封包格式
Application of workflow engine in vivo marketing automation | engine 03
随机推荐
Use of delete
Lamda表达式使用
游戏中的数学之各种插值
Matplotlib draws a line graph
list分为多个子list集合
ELF 格式详解(一)
百度地图、高德地图、腾讯地图三位一体地图定位开发
Virbox 编译器,支持全平台全架构的源代码加密
剑指 Offer 48. 最长不含重复字符的子字符串
Shell脚本编程详解
分页助手PageHelper的使用
restTemplate返回字符乱码问题
Linux uses Yum to quickly install mysql
Anaconda常用命令
mongodb上手
动态创建对象时候为什么使用new,而不是malloc
TypeScript在Cocos中的具体使用
Self defined multiple code of station B
Elk+filebeat build distributed logs
Batch efficient feature decomposition of eccv2022 small and medium-sized matrices