If Collection defines hasNext () instead of iterator (). hasNext (), we could write a loop easier:
while(collection.hasNext()){…}
instead:
Iterator it= collection.iterator(); While(it.hasNext()){…}
Of course, I know a simple way for a for loop for(E e:collection) .
Why is there an Iterator interface?
java iterator collections design
卢 声 远 Shengyuan Lu
source share