packagecom.jakin.util;
importjava.util.ArrayList;
importjava.util.Collection;
importjava.util.Collections;
importjava.util.List;
importorg.apache.commons.collections.CollectionUtils;
importorg.apache.commons.lang.ArrayUtils;
publicclassCollectionUtilsTest{
@SuppressWarnings("unchecked")
publicstaticvoidmain(String[] args){
List aList =newArrayList();
aList.add("aaa");
aList.add("bbb");
aList.add("ccc");
List bList =newArrayList();
bList.add("aaa");
bList.add("ddd");
bList.add("eee");
// 并集
Collection
// 交集
Collection
// 是否存在交集
booleanisContained = CollectionUtils.containsAny(aList, bList);
// 交集的补集
Collection
// 集合相减
Collection
// 排序
Collections.sort((List
Collections.sort((List
Collections.sort((List
Collections.sort((List
// 测试
System.out.println("A: "+ ArrayUtils.toString(aList.toArray()));
System.out.println("B: "+ ArrayUtils.toString(bList.toArray()));
System.out.println("A has one of B? : "+ isContained);
System.out.println("Union(A, B): "
+ ArrayUtils.toString(unionList.toArray()));
System.out.println("Intersection(A, B): "
+ ArrayUtils.toString(intersectionList.toArray()));
System.out.println("Disjunction(A, B): "
+ ArrayUtils.toString(disjunctionList.toArray()));
System.out.println("Subtract(A, B): "
+ ArrayUtils.toString(subtractList.toArray()));
}
}