for each loop and method code example
Example 1: for-each loop in java
// syntax
for(<DataType of array><variablename> : <Array to be iterated>)
{
// code
}
Example 2: for-each loop in java
// for each loop in java example
import java.util.*;
public class ForEachLoopExample
{
public static void main(String[] args)
{
int[] numbers = {2, 4, 6, 8, 10};
// for each loop
for(int n : numbers)
{
System.out.println(n);
}
}
}