How to Traverse ArrayList using for each loop in Java
Tags: ArrayList
In this Java core tutorial we learn how to traverse through all element of an java.util.ArrayList using for each loop in Java programming language.
How to traverse through an ArrayList using for each loop in Java
In the following Java program, we show how to traverse through all elements of an ArrayList using for each loop.
ArrayListForEachLoopExample1.java
import java.util.ArrayList;
import java.util.List;
public class ArrayListForEachLoopExample1 {
public static void main(String... args) {
List<String> list = new ArrayList<>();
list.add("Java");
list.add("Kotlin");
list.add("Groovy");
// For each over all elements of an ArrayList
for(String item : list) {
System.out.println(item);
}
}
}
Java
Kotlin
Groovy
Happy Coding 😊
Related Articles
Java Convert Array to ArrayList
Java Insert Element to ArrayList at Specified Index
Java Get Minimum Value in ArrayList
How to Traverse ArrayList using Iterator in Java
How to Traverse ArrayList using forEach() method in Java
Java Convert ArrayList to LinkedList
Java Convert ArrayList to Array
Java Convert ArrayList to String
Java Convert ArrayList to Comma Separated String
Java Convert ArrayList to HashSet
Java Create New Array with Class Type and Length
Java Create ArrayList using List Interface