填充容器
public static void main(String[] args) {
//复制相同的对象传递给List构造器
List<String> strList=new ArrayList<String>(Collections.nCopies(4,"Hello"));
System.out.println(strList);
//fill也是复制同一个对象引用填充整个容器
//只对List对象有用,但是只能替换list中存在的元素,不能添加新元素
Collections.fill(strList,"World");
System.out.println(strList);
}
//结果
[Hello, Hello, Hello, Hello]
[World, World, World, World]