序
这里简单介绍下,如何使用apache commons以及guava的类库来计算集合的交差并集。
maven
com.google.guava guava 22.0 org.apache.commons commons-collections4 4.1
guava
//交集 SetintersectionSet = Sets.intersection(set1, set2); //差集 Set subtractSet = Sets.difference(set1, set2); //并集 Set unionSet = Sets.union(set1, set2);
commons-collection4
//交集 CollectionintersectionSet = CollectionUtils.intersection(set1, set2); //差集 Collection subtractSet = CollectionUtils.subtract(set1, set2); //并集 Collection unionSet = CollectionUtils.union(set1, set2);