This happens behind the scenes if we use the extended for loop with arrays:
int[] array = {1,2,3,4,5}; for($i = 0; $i<array.length; $i++) { int i = array[$i];
$i is just a placeholder for an unnamed inner loop variable. See what happens: you assign a new value to i , but i loaded with the next element in the array in the next iteration.
So, practically speaking, we cannot use the variable declared in the extended loop to modify the underlying array.
Link: JLS 3.0, 14.14.2
source share