loop through every item in array java while code example

Example 1: lopp array java

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.
}

Example 2: 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);
    }
    
 
  }
}

Tags:

Java Example