Chapter 28. Iterator

In ordinary development, you add behavior by extending classes with new methods. Occasionally, though, you need to add behavior to a collection of instances of the classes you create. The Java class libraries provide many features for working with collections, including behaviors for sorting, shuffling, reversing, and iterating over a collection. You may find, however, that you need iteration behaviors that go beyond those built into Java. In particular, if you need to add type safety to iteration, or if you need to create a new type of collection, you will probably need to develop your own iterator code to walk through the collection. The intent of the ITERATOR pattern is to provide a way to access the elements of collection ...

Get Design Patterns Java™ Workbook 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.