`
asgab
  • 浏览: 42010 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

CollectionUtils 使用

    博客分类:
  • java
 
阅读更多

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( ) ) );
	}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics