-
体系结构
2.遍历
如下单列集合
Collection<String> coll=new ArrayList<>();
coll.add("zhangsan");
coll.add("lisi");
coll.add("wangwu");
增强for
//增强for
for (String s : coll) {
System.out.println(s);
}
forEach
//forEach
coll.forEach(new Consumer<String>() {
@Override
public void accept(String s) {
System.out.println(s);
}
});
//forEach---简化--->lamada
coll.forEach(s->System.out.println(s));
iterator
//迭代器遍历
Iterator<String> it = coll.iterator();
while (it.hasNext()) {
String str= it.next();
System.out.println(str);
}