= Solution
Use the <iterator pattern> when clients need \b[sequential access to a collection's elements without depending on its internal representation]. A collection supplies a traversal object with operations such as `hasNext` and `next`; the client uses the same traversal interface whether the collection is an <array>, <linked list>, or another <data structure>.
The <iterator> keeps the traversal state separate from both the collection and client, so several independent traversals can coexist and the representation can change without rewriting traversal logic. It can also support incremental or <lazy evaluation> of elements. Exhaustion must have defined behavior, and a mutable collection must define how updates during traversal are handled. The pattern does not by itself promise that arbitrary concurrent modifications are safe.
Back to article page