There Is No for In Java: Using the for Loop Enhancements

In some programming languages, it's very easy to iterate through a list or an array, automatically repeating through a loop "for each" item in the list and assigning the item to a local variable. I once started to tell a colleague how I thought the for loop in Java was broken, because it didn't have a for-each. What actually came out of my mouth was "There is no for in Java." My friend was also an experienced Java developer, and he responded with "Are you crazy? Of course there's a for in Java!" For a long time after that he continued to tease me, periodically reminding me that ...

Get Wicked Cool Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.