Chapter 19. The Iterator Pattern

The Iterator pattern is one of the simplest and most frequently used of the design patterns. It allows you to move through a list or collection of data using a standard interface without having to know the details of that data's internal representations. You can also define special iterators that perform some special processing and return only specified elements of the data collection.

Motivation

The Iterator pattern is useful because it provides a defined way to move through a set of data elements without exposing what is taking place inside the class. It is an interface; thus you can implement it in any way that is convenient for the data that you are returning. Design Patterns suggests that a suitable interface ...

Get Java™ Design Patterns: A Tutorial now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.