org.apache.commons.collections4.CollectionUtils 操作集合 String[] arrayA = new String[] { "1", "2", "3", "3", "4", "5" }; String[] arrayB = new String[] { "3", "4", "4", "5", "6", "7" }; List a = Arrays.asList(arrayA); List b = Arrays.a
String[] arrayA = new String[] { "1", "2", "3", "3", "4", "5" }; String[] arrayB = new String[] { "3", "4", "4", "5", "6", "7" }; Lista = Arrays.asList(arrayA); List b = Arrays.asList(arrayB); //并集 Collection union = CollectionUtils.union(a, b); //交集 Collection intersection = CollectionUtils.intersection(a, b); //交集的补集 Collection disjunction = CollectionUtils.disjunction(a, b); //集合相减 Collection subtract = CollectionUtils.subtract(a, b); // Collections.sort((List ) union); // Collections.sort((List ) intersection); // Collections.sort((List ) disjunction); // Collections.sort((List ) subtract); System.out.println("A: " + a.toArray()); System.out.println("B: " + b.toArray()); System.out.println("--------------------------------------------"); System.out.println("Union(A, B): " + union.toArray());//并集 System.out.println("Intersection(A, B): " + intersection.toArray());//交集 System.out.println("Disjunction(A, B): " + disjunction.toArray());//交集的补集 System.out.println("Subtract(A, B): " + subtract.toArray());//集合想减,A-B