java loop through array

Java
import java.util.*;

public class HelloWorld {
  public static void main(String[] args) {
    
    // you can define the type of list you want to init - String int etc inside <yourType> eg. <String>
    List<String> family = new ArrayList();
    
    family.add("Member1");
    family.add("Member2");
    family.add("Member3");
    family.add("Member4");
    family.add("Member5");
    
    // print array 
    for(String name : family)
    {
    	System.out.println(name);
    }
    
 
  }
}
public class HelloWorld {
  public static void main(String[] args) {
    
    // init array
    String[] family = new String[] {"Member1", "Member2", "Member3", "Member4", "Member5"};
    
    // print array 
    for(String name : family)
    {
    	System.out.println(name);
    }
    
 
  }
}
// Java program to iterate over an array 
// using for loop 
import java.io.*; 
class GFG { 
  
    public static void main(String args[]) throws IOException 
    { 
        int ar[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 
        int i, x; 
  
        // iterating over an array 
        for (i = 0; i < ar.length; i++) { 
  
            // accessing each element of array 
            x = ar[i]; 
            System.out.print(x + " "); 
        } 
    } 
} 
For(<DataType of array/List><Temp variable name>   : <Array/List to be iterated>){
    System.out.println();
//Any other operation can be done with this temp variable.
}// Java program to iterate over an array 
// using for loop 
import java.io.*; 
class GFG { 
  
    public static void main(String args[]) throws IOException 
    { 
        int ar[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 
        int i, x; 
  
        // iterating over an array 
        for (i = 0; i < ar.length; i++) { 
  
            // accessing each element of array 
            x = ar[i]; 
            System.out.print(x + " "); 
        } 
    } 
} 
Source

Also in Java: