Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Use of For-Each loops

$
0
0
While reading through Effective Java by Joshua Bloch, he mentions the use of the for-each loop when cycling through an array. I did a small test to get comfortable with it and got what I wanted but noticed that you can not manipulate the array being iterated over by any means (at least ones I'm capable of). So I have two questions.
1. For the pro's out there. Are these preferred to iterate arrays over the traditional for loop? Should I make a habit of it? (oracle says it's preferred but I want opinions)
2. What's the technical aspect behind the reason you can not manipulate the array inside a for-each loop? If nobody can answer this or it's just too intricate to explain, I can always go bug oracle. B)

Viewing all articles
Browse latest Browse all 51036

Trending Articles