[Commons]——集合操作

来源:互联网 发布:量身高的软件 编辑:程序博客网 时间:2024/05/29 10:55
public class test4 {//Commons集合操作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);set2.add(6);//并集Collection<Integer> col=CollectionUtils.union(set1, set2);for(Integer temp:col){System.out.print(temp+"  ");}System.out.println();//交集col=CollectionUtils.intersection(set1, set2);//col=CollectionUtils.retainAll(set1, set2);for(Integer temp:col){System.out.print(temp+"  ");}System.out.println();//差集col=CollectionUtils.subtract(set2, set1);for(Integer temp:col){System.out.print(temp+"  ");}}}

0 0