java for each i in code example
Example 1: foreach java
for (String name : names) {
System.out.println(name);
}
Example 2: java foreach
List<String> someList = new ArrayList<String>();
for (String item : someList) {
System.out.println(item);
}
Example 3: for-each loop in java
import java.util.*;
public class ForEachLoopExample
{
public static void main(String[] args)
{
int[] numbers = {2, 4, 6, 8, 10};
for(int n : numbers)
{
System.out.println(n);
}
}
}
Example 4: how to do for each in java
for(int i : alist)
{
i+=1
}