Apache common collection的使用(3)
来源:互联网 发布:vc打印机编程 编辑:程序博客网 时间:2024/06/10 15:45
集合的使用
并集
Collection collection = CollectionUtils.union(set1, set2);
交集
collection = CollectionUtils.intersection(set1, set2);
差集
collection = CollectionUtils.subtract(set1, set2);
程序
package cn.others;import org.apache.commons.collections4.CollectionUtils;import java.util.Collection;import java.util.HashSet;import java.util.Set;/** * @author Duoduo * @version 1.0 * @date 2017/4/15 15:15 */public class Test6 { public static void main(String[] args){ Set<Integer> set1 = new HashSet<Integer>(); set1.add(1); set1.add(2); set1.add(3); set1.add(4); Set<Integer> set2 = new HashSet<Integer>(); set2.add(3); set2.add(4); set2.add(5); System.out.println("********* 并集 **********"); Collection collection = CollectionUtils.union(set1, set2); System.out.println(collection); System.out.println("********* 交集 **********"); collection = CollectionUtils.intersection(set1, set2); System.out.println(collection); System.out.println("********* 差集 **********"); collection = CollectionUtils.subtract(set1, set2); System.out.println(collection); }}
运行结果
* 并集 **
[1, 2, 3, 4, 5]
* 交集 **
[3, 4]
* 差集 **
[1, 2]
0 0
- Apache common collection的使用(3)
- Apache common collection的使用(1)
- Apache common collection的使用(2)
- apache-collection的使用
- Apache Common Pool的使用
- apache common-dbutils 的使用
- Apache common FTP 的使用
- apache-common pool的使用
- apache-common pool的使用
- Apache Common Pool的使用
- apache-common pool的使用
- apache-common pool的使用
- apache-common pool 的使用
- 使用SolrCloud出现org.apache.solr.common.SolrException: Collection not found: my_solr2
- Apache Common HttpClient的使用之道
- 关于apache common lang ArrayUtils的使用
- Apache common-fileupload 组件的使用实例
- Java Collection Framework扩展Apache Common Collections介绍
- 【CSS】3.演示示例
- mysql索引优化篇(一)
- java保留整数
- 黏滞位的作用以及如何设置
- 解决spring4.x中的MappingJacksonHttpMessageConverter错误
- Apache common collection的使用(3)
- [Boolan] C++第十三周 C++设计模式(三)
- 跟着第一行代码学安卓(第二版书)-1
- NIO Buffer To String
- BP学习记录
- bzoj1420&bzoj1319 Discrete Root
- Linux服务器基本安全防范
- BootStrap(二) -- 在表格行添加按钮并取得选中行数据
- HDU