for item in array java code example
Example 1: for each java
int [] intArray = { 10, 20, 30, 40, 50 };
for( int value : intArray ) {
System.out.println( value );
}
Example 2: java foreach
List<String> someList = new ArrayList<String>();
for (String item : someList) {
System.out.println(item);
}
Example 3: lopp array java
For(<DataType of array/List><Temp variable name> : <Array/List to be iterated>){
System.out.println();
}
Example 4: loop through array java
import java.util.*;
public class HelloWorld {
public static void main(String[] args) {
List<String> family = new ArrayList();
family.add("Member1");
family.add("Member2");
family.add("Member3");
family.add("Member4");
family.add("Member5");
for(String name : family)
{
System.out.println(name);
}
}
}