Iterating List using Loop Java

In this tutorial, I am just sharing simple snippet program about, How to perform Iterating List using Loop Java. The example java program were tested with environment and output is shared in the same post.

IteratingListUsingForLoop.java

package com.dineshkrish;
import java.util.ArrayList;
import java.util.List;
public class IteratingListUsingForLoop {
public static void main(String[] args) {
// Defining ArrayList Object
List<String> strList = new ArrayList<String>();
// Adding the Elements to List
strList.add("One");
strList.add("Two");
strList.add("Three");
strList.add("Four");
strList.add("Five");
strList.add("Six");
// Iterating the List using For Loop
for (int i = 0; i < strList.size(); i++) {
System.out.println(strList.get(i));
}
}
}

Output

—————–
One
Two
Three
Four
Five
Six

Tags:

No responses yet

Leave a Reply

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