<<< Iterators | Index | Common collection classes >>> |
public interface Iterator<E> { boolean hasNext(); // returns true if the iteration has more elements E next(); // returns the next element in the iteration void remove(); // removes the last element that was returned by next() }
Why use iterators instead of the for-each construct?
To remove selective elements during iteration. The for-each construct hides the iterator, so you cannot remove elements.
Iterate over multiple collections in parallel.
<<< Iterators | Index | Common collection classes >>> |