The foreach Loops in Java

JDK 1.5 presented another for construct, which is known as foreach loop or extended for loop. This construct empowers you to cross the complete array successively without utilizing an extra variable.

Sample Implementation:

public class Mytestarray {
public static void main(string[] args) {
double[] myarray = {0.5, 1.2, 2.2, 3.4, 4.7};
for (double i: myarray) {
System.out.println(i);
}
}

This would deliver the accompanying result:
0.5 1.2 2.2 3.4 4.7