Iterator接口的使用方法
public class IteratorDemo {
public static void main(String[] args) {
Collection<String> coll = new ArrayList<String>();
coll.add("abc1");
coll.add("abc2");
coll.add("abc3");
coll.add("abc4");
Iterator<String> it = coll.iterator();
while (it.hasNext()) {
String s = it.next();
System.out.println(s);
}
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a3c4c2e4d0dad5c5f1ee05ec0119c047.png)
迭代器的转型
Collection coll = new ArrayList();
coll.add("abc");
coll.add("def");
coll.add("opq");
Iterator it = coll.iterator();
while (it.hasNext()) {
String str = (String) it.next();
System.out.println(str.length());
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e4a40bc0c1352bbd30b513e8ec3886b7.png)