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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access