【发布时间】:2011-04-07 02:38:41
【问题描述】:
如果 Collection 定义 hasNext() 而不是 iterator().hasNext(),我们可以更轻松地编写循环:
while(collection.hasNext()){…}
代替:
Iterator it= collection.iterator();
While(it.hasNext()){…}
当然,我知道循环 for(E e:collection) 存在的简单方法。
接口Iterator为什么存在?
【问题讨论】:
标签: java collections iterator