当前位置:网站首页>Union, intersection and difference tool classes based on Apache set Toolkit
Union, intersection and difference tool classes based on Apache set Toolkit
2022-04-21 23:50:00 【Curious rookie】
Combine 、 intersection 、 Difference set 、 What is the concept of complement ?
One 、 rely on
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
Two 、 Tool class
import org.apache.commons.collections4.CollectionUtils;
import java.util.List;
public class ListUtils {
// Get the union of two sets ( Automatic weight removal )
public static <T> List<T> getUnion(List<T> list1, List<T> list2){
List<T> union = (List<T>) CollectionUtils.union(list1, list2);
return union;
}
// Get the intersection of two sets
public static <T> List<T> getIntersection(List<T> list1,List<T> list2){
List<T> intersection = (List<T>) CollectionUtils.intersection(list1, list2);
return intersection;
}
// Gets the complement of the intersection of two sets namely list1 + list2 - intersection
public static <T> List<T> getDisjunction(List<T> list1,List<T> list2){
List<T> disjunction = (List<T>)CollectionUtils.disjunction(list1, list2);
return disjunction;
}
// Get the difference set of two sets list1 - intersection
public static <T> List<T> getSubtract(List<T> list1,List<T> list2){
List<T> subtract = (List<T>)CollectionUtils.subtract(list1, list2);
return subtract;
}
}
3、 ... and 、 test
public static void main(String[] args) {
List<Integer> list1 = Stream.of(1, 2, 3).collect(Collectors.toList());
List<Integer> list2 = Stream.of(2, 3, 4).collect(Collectors.toList());
System.out.println("list1:" + list1);
System.out.println("list2:" + list2);
List<Integer> union = getUnion(list1, list2);
System.out.println("list1-list2 Combine union:" + union);
List<Integer> intersection = getIntersection(list1, list2);
System.out.println("list1,-list2 intersection :" + intersection);
List<Integer> disjunction = getDisjunction(list1, list2);
System.out.println("list1-list2 Complement of intersection :" + disjunction);
List<Integer> subtract = getSubtract( union,list1);
System.out.println("union-list1 Difference set :" + subtract);
}
list1:[1, 2, 3]
list2:[2, 3, 4]
list1-list2 Combine union:[1, 2, 3, 4]
list1,-list2 intersection :[2, 3]
list1-list2 Complement of intersection :[1, 4]
union-list1 Difference set :[4]
版权声明
本文为[Curious rookie]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212340347324.html
边栏推荐
- Leetcode daily question 824 Goat Latin
- 分布式gns3
- 6、協議層次化和服務模型(重點)
- 341-Linux 连接数据库
- CatBoost如何处理非数值型(Object)数据
- Buuctf question brushing record
- . 101 keyboard events
- 找出大于X的第一个质数(DAY 42)
- 通过点击导入的文件或点击组件进入对应的组件页面进行编辑
- What is the difference between machine learning, deep learning, neural network and deep neural network?
猜你喜欢

341-Linux 连接数据库

What is the difference between machine learning, deep learning, neural network and deep neural network?
Technology, products and brand are not problems. For SAIC Audi, these two points may be life and death

vmware-vmx. Exe could not end the process

Leetcode:443 Compressed string

Naming of STM32 & stm8 Series MCU products

JDBC概念 在idea里创建JDBC项目步骤

Find the first prime number greater than x (day 42)

数据库连接池和Druid的使用

Robot OS驱动开发
随机推荐
Storage group physical quantity entity path
Necessary skills for large factory interview, Android audio and video framework
如何让知识图谱辅助多轮对话
分布式gns3
6、协议层次化和服务模型(重点)
Cvpr2022 oral | contribution imbalance in multimodal learning
A collection of large factories and face classics. Do you know these knowledge points
SolidWorks怎么设置运动行程和角度
【接口测试基础】第五篇 | 接口用例设计详解
5. Network structure and ISP, packet delay, loss, throughput
Leetcode daily question 824 Goat Latin
leetcode:440. The k-th smallest digit in dictionary order
(Reprint) MySQL read-write separation -- cluster and high concurrency
【acwing】1125. 牛的旅行***(floyd)
Solution of mountain torrent disaster monitoring and early warning system
[super detailed explanation plus source code and test results] a series of operation collection of sequence table
leetcode:386. 字典序排数
【MYSQL优化1】mysql优化思路
【源码篇】LinkedBlockingQueue源码超详细解读
7.5 thread waiting for termination