CollectionUtils 使用

public static void main(String[] args) {
		String[] arrayA = new String[] { "a", "b", "c", "d", "e", "d" };
		String[] arrayB = new String[] { "d", "c", "2", "d", "e", "b" };

		List a = 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: " + ArrayUtils.toString( a.toArray( ) ) );
		System.out.println( "B: " + ArrayUtils.toString( b.toArray( ) ) );
		System.out.println( "Union: " + ArrayUtils.toString( union.toArray( ) ) );
		System.out.println( "Intersection: " + 
		                    ArrayUtils.toString( intersection.toArray( ) ) );
		System.out.println( "Disjunction: " + 
		                    ArrayUtils.toString( disjunction.toArray( ) ) );
		System.out.println( "Subtract: " + ArrayUtils.toString( subtract.toArray( ) ) );
	}
 

你可能感兴趣的:(Collection)