Enhanced Loop Java Example

In this tutorial, We will show you How Iterate an array object using Enhanced Loop Java Example. The below Java snippet code will give you idea about the performing the iteration over the array object. The Enhanced for loop feature introduced JDK 5.0 version on wards. If you are trying to run this example in lower JDK version. It won`t work.

EnhancedForLoop.java

package com.dineshkrish;
public class EnhancedForLoop {
public static void main(String[] args) {
// Defining the String array object
String[] countries = {"US", "Canada", "India", "China", "Japan", "Netherlands"};
System.out.println("Country List");
System.out.println("-----------------------------");
// Iterating the array object using Enhanced For Loop
for (String country : countries) {
System.out.println(country);
}
}
}

Output

Country List
—————————–
US
Canada
India
China
Japan
Netherlands

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *