I understand that new for each loop works with Iterable and arrays, but I don\'t know what goes behind the scenes when working with arrays.
Can anyone help me under
A bit late, but here it is.
The compiler knows if you are using the for-each loop statement for a collection or for an array.
If used for collection,
the compiler translates the for-each loop to the equivalent for loop using an Iterator
.
If used for an array, the compiler translates the for-each loop to the equivalent for loop using an index variable.
Here is a description at oracle.com