11.6 Iterator, Iterable*
In many programs, not only does the individual data play a role, but also collections of this data are meaningful. For example, arrays are collections as are standard data structures like ArrayList, HashSet , or files. A collection is mainly characterized by methods that add and remove data and check for the presence of elements. Of course, each of these mutable data structures has a specific API, but in the spirit of good object-oriented (OO) modeling, describing this behavior in interfaces is desirable.
Two interfaces stand out in particular:
-
Iterator : Provides a way to run through collections step by step.
-
Iterable: Provides such an Iterator, so it’s an Iterator producer.
11.6.1 The Iterator Interface ...
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