This won't work if you want to change the values. In that case you need to have the indices available. You can use traditional for loops for that (as referenced in the other answers) or, in Java 8, IntStream: