Interesting trick with For Loop – Using the Foreach loop in Java

For-Each Example: Enhanced for Loop to Iterate Java Array

For-Each Loop is another form of for loop used to traverse the array. for-each loop reduces the code significantly and there is no use of the index or rather the counter in the loop.

Syntax:

How to Loop/Iterate an array in Java

Let us take the example using a String array that you want to iterate over without using any counters.

Consider a String array arrData initialized as follows:

top
X
Welcome to Our Website
Welcome to WPBot
wpChatIcon