package com.itheima.testinterfacess;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class AddingGroups {
public static void main(String[] args) {
Integer [] moreInts = {6,7,8,9,10};
/**
public static <T> List<T> asList(T... a) {
return new ArrayList<>(a);
}
*/
List<Integer> asList = Arrays.asList(moreInts);
//ArrayList()有一个含参构造方法:public ArrayList(Collection<? extends E> c)里面含有Collection的实现类就可以了
Collection<Integer> collection = new ArrayList<Integer>(Arrays.asList(1,2,3,4,5));
//把整个集合添加进来
collection.addAll(asList);
for (Integer integer : collection) {
System.out.print(integer);
}
System.out.println("------------------------------------------");
Collections.addAll(collection, 11,12,13,14,15);
for (Integer integer : collection) {
System.out.print(integer);
}
System.out.println("------------------------------------------");
Collections.addAll(collection, moreInts);
for (Integer integer : collection) {
System.out.print(integer);
}
}
}
输出结果:
12345678910——————————————
123456789101112131415——————————————
123456789101112131415678910