list交并补差集合

list交并补差集合

工具类依赖

xml 复制代码
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.8.1</version>
</dependency>

<dependency>
    <groupId>commons-collections</groupId>
	<artifactId>commons-collections</artifactId>
	<version>3.2</version>
</dependency>

参考代码

java 复制代码
		// 交并补差
        List<Integer> list1 = Lists.newArrayList(1,2,3);
        List<Integer> list2 = Lists.newArrayList(3,4,5);
        List<Integer> intersection = (List<Integer>) CollectionUtils.intersection(list1, list2);
        log.info("list1与list2交集:[{}]",intersection);

        List<Integer> unionResult = (List<Integer>) CollectionUtils.union(list1, list2);
        log.info("list1与list2并集:[{}]",unionResult);

        List<Integer> subtractList = (List<Integer>) CollectionUtils.subtract(list1, list2);
        log.info("list1与list2差集:[{}]",subtractList);

        List<Integer> subtractListSecond = (List<Integer>) CollectionUtils.subtract(list2, list1);
        log.info("list2与list1差集:[{}]",subtractListSecond);

        List<Integer> disjunctionList = (List<Integer>) CollectionUtils.disjunction(list1, list2);
        log.info("list1与list2补集:[{}]",disjunctionList);

00:05:52.126 [main] INFO com.geekmice.sbeasypoi.service.impl.ds - list1与list2交集:[[3]]

00:05:52.136 [main] INFO com.geekmice.sbeasypoi.service.impl.ds - list1与list2并集:[[1, 2, 3, 4, 5]]

00:05:52.147 [main] INFO com.geekmice.sbeasypoi.service.impl.ds - list1与list2差集:[[1, 2]]

00:05:52.147 [main] INFO com.geekmice.sbeasypoi.service.impl.ds - list2与list1差集:[[4, 5]]

00:05:52.149 [main] INFO com.geekmice.sbeasypoi.service.impl.ds - list1与list2补集:[[1, 2, 4, 5]]

相关推荐
CS创新实验室18 分钟前
计算机考研之数据结构:大 O 记号
数据结构·考研
wen__xvn2 小时前
每日一题洛谷P1914 小书童——凯撒密码c++
数据结构·c++·算法
BUG 劝退师2 小时前
八大经典排序算法
数据结构·算法·排序算法
早起的年轻人3 小时前
Java List 自定义对象排序 Java 8 及以上版本使用 Stream API
java·windows·list
jay丿3 小时前
Redis 中列表(List)常见命令详解
数据库·redis·list
小小小白的编程日记3 小时前
List的基本功能(1)
数据结构·c++·算法·stl·list
_Itachi__3 小时前
LeetCode 热题 100 283. 移动零
数据结构·算法·leetcode
柃歌3 小时前
【UCB CS 61B SP24】Lecture 5 - Lists 3: DLLists and Arrays学习笔记
java·数据结构·笔记·学习·算法
商bol454 小时前
复习dddddddd
数据结构·c++·算法
干炒 牛河7 小时前
数据结构:哈希表(unordered_map)
数据结构·算法·散列表