Intent
Provide a way to move through a list of collection or aggregated objects without knowing its internal representations.
Where to use & benefits
- Use a standard interface to represent data objects.
- Use s standard iterator built in each standard collection, like List, Sort, or Map.
- Need to distinguish variations in the traversal of an aggregate.
- Similar to Enumeration class, but more effective.
- Need to filter out some info from an aggregated collection.
Structure

Participants
Iterator (java.util.Iterator)
defines an interface for accessing and traversing elements.
ConcreteIterator (java.util.AbstaractList#iterator() (ArrayListIterator))
implements the Iterator interface and keeps track of the current position in the traversal of the aggregate.
Aggregate (java.util.List)
defines an interface for creating an Iterator object
ConcreteAggregate (java.util.ArrayList)
implements the Iterator creation interface to return an instance of the proper ConcreteIterator
Example
In the demonstration application, AppletPainter class uses Java ArrayList Iterator facility to iterate the Command objects in the CommandContainer class.
Class Diagram

Source Code Links
- AppletPainter (Client)