In this java article, we will be looking for-each loops in Java. For each loops work similar to FOR loop, but it does not require an initialization parameter as counter.
They are mostly used to iterate within arrays and collections.
Lets look to syntax of multidimensional arrays in Java.
int[] x = {5,9,12};
for(int i : x)
{
System.out.println(i);
}
Lets see it in Java array example.
In above example, we declared a variable "x" as type of array and we added 3 item to it. With a FOR EACH loop, we iterated inside the array and print the values out to console.