Iterator 使用代码如下:
List list = new ArrayList();
Iterator it = list.iterator();
while(it.hasNext()){
String obj = it.next();
System.out.println(obj);
}
Iterator 的特点是只能单向遍历,但是更加安全,因为它可以确保,在当前遍历的集合元素被更改的时候,就会抛出 ConcurrentModificationException异常。

Was this helpful?

0 / 0

发表回复 0

Your email address will not be published.