This chapter addresses the following question: suppose that a variable holds a collection of objects; what code should you write to examine its elements? Technically speaking, this question is asking about iterables and iteration. A collection is an iterable, and the mechanism for examining its elements is iteration. The question can be rephrased as “How should I iterate through an iterable?”
Java supports multiple ways to iterate through an iterable, which can be divided into two categories: external iteration, in which you write a loop that examines each element of the iterable; and internal ...