Skip to content
Advertisement

Tag: syntactic-sugar

How does the Java ‘for each’ loop work?

Consider: What would the equivalent for loop look like without using the for each syntax? Answer Note that if you need to use i.remove(); in your loop, or access the actual iterator in some way, you cannot use the for ( : ) idiom, since the actual iterator is merely inferred. As was noted by Denis Bueno, this code works

Advertisement