Collection.addAll的用法

Collection collection=new ArrayList(Arrays.asList(1,2,3,4,5));
		Iterator iterator=collection.iterator();
		while (iterator.hasNext()) {
			System.out.println(iterator.next());
		}
		System.out.println("******************************************");
		collection.addAll(Arrays.asList(6,7,8,9,10));
		iterator=collection.iterator();
		while (iterator.hasNext()) {
			System.out.println(iterator.next());
		}
		System.out.println("******************************************");
		Collections.addAll(collection, 11,12,13,14,15);
		iterator=collection.iterator();
		while (iterator.hasNext()) {
			System.out.println(iterator.next());
		}
		System.out.println("******************************************");
		collection.add(16);
		iterator=collection.iterator();
		while (iterator.hasNext()) {
			System.out.println(iterator.next());
		}

 

运行结果:

1
2
3
4
5
******************************************
1
2
3
4
5
6
7
8
9
10
******************************************
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
******************************************
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

 

你可能感兴趣的:(Java泛型)