Concept

How does Java use variables and collections in enhanced for loops?

ComputerScienceOne / Enhanced For Loops

"The code (int a : arr) should be read as “for each integer element a in the collection arr ...” Within the enhanced for loop, the variable a will be automatically updated for you on each iteration. Outside the loop body, the variable a is out-of-scope. Java allows you to use an enhanced for loop with any array or collection (technically, anything that implements the Iterable interface). One example is a List , an ordered collection of elements. Code Sample 28.6 contains an example."

Related Ideas