Because in your enhanced for loop, the variable
n is a
local variable which is reassigned to a new
String returned from
n.replace("\"", "") and doesn't affect the value stored in the List. The loop is functionally equivalent to
You can easily see that this won't change the value of the String at
names.get(i).