1int [] intArray = { 10, 20, 30, 40, 50 };
2
3for( int value : intArray ) {
4 System.out.println( value );
5}
1//itemset contains variables of type <Data Type>
2for(<Data Type> item : itemset) {
3 //loop
4}
1List<String> someList = new ArrayList<String>();
2// add "monkey", "donkey", "skeleton key" to someList
3for (String item : someList) {
4 System.out.println(item);
5}
1// syntax
2for(<DataType of array><variablename> : <Array to be iterated>)
3{
4 // code
5}
1// for each loop in java example
2import java.util.*;
3public class ForEachLoopExample
4{
5 public static void main(String[] args)
6 {
7 int[] numbers = {2, 4, 6, 8, 10};
8 // for each loop
9 for(int n : numbers)
10 {
11 System.out.println(n);
12 }
13 }
14}