0
what is a for each loop in java and how can you implement it in a program
1 Answer
+ 1
A for-each loop iterates over every element of the given container.
For example:
If you have an array called names and you want to print every name to the console, you would do it like this:
String names[] = new String[] {"John", "Mary", "Luke");
for(String name : names){
System.out.println(name);
}