java.util · java.base · since Java 1.2

Iterator

declaration
public interface Iterator<E>

The cursor protocol behind every for-each: hasNext/next, plus remove() — the only legal way to delete during iteration of most collections.

Key methods

boolean hasNext() / E next()The stepping pair; next() past the end throws NoSuchElementException.
default void remove()Delete the last-returned element without ConcurrentModificationException — the only safe removal mid-iteration.
default void forEachRemaining(Consumer<? super E>)Drain the rest of the iterator in one call.