Check out example codes for "for each java". It will help you in understanding the concepts better.

Code Example 1

List<String> someList = new ArrayList<String>();
// add "monkey", "donkey", "skeleton key" to someList
for (String item : someList) {
    System.out.println(item);
}

Code Example 2

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);
      }
   }
}

Code Example 3

for (int i=0; i<arr.length; i++) 
{ 
    type var = arr[i];
    statements using var;
}

Code Example 4

int [] intArray = { 10, 20, 30, 40, 50 };
        
for( int value : intArray ) {
   System.out.println( value );
}

Code Example 5

// definition eine Datenstruktur, hier ein Array mit 9 Werten
int[] array = new int[]{4, 8, 4, 2, 2, 1, 1, 5, 9};

// ForEach Schleife
for( int k: array )
{
	System.out.println("k = "+k);
}

Code Example 6

for (int i : array) { 
    System.out.println(i);
}

Learn ReactJs, React Native from akashmittal.com