List<StringAddress> list= new ArrayList<StringAddress>(
Collections.nCopies(4, new StringAddress("Hello")));
Collections.fill(list, new StringAddress("World!")); //fill()只能替换已经在list中存在的元素
Set<String> set = new HashSet<String>();
Collections.addAll(set, "one two three four five".split(" "));
Iterator<String> iterator = set.iterator();
while (iterator.hasNext()) {
Stringstring = (String) iterator.next();
System.out.println(string);
}
for (String str : set) {
System.out.println(str);
}
简单的容器分类常用的方法填充容器: List<StringAddress> list= new ArrayList<StringAddress>( Collections.nCopies(4, new StringAddress("Hello")));Collections.fill(list, new StringAddress("World!")); //fill()只能替换