Properties:
- Enables traversal of collections.
Implementation:
- Aggregate declares method to return iterator of the collection.
- ConcreteAggregate represents the collection which creates an iterator for traversal of contained objects.
- Iterator declares methods to iterate over a collection
- ConcreteIterator a collection specific implementation of Iterator interface.
Java Standard Library Implementations:
Example Usage:
List<File> paths=...;
// obtain iterator
Iterator<File> pathsIterator = paths.iterator();
while (pathsIterator.hasNext()) {
File path = pathsIterator.next();
System.out.println(path.getName());
}
Comments
Post a Comment