In Java Collections Framework, ArrayList implements the Iterable interface which offering iterator, so beside the traditional while and for loop, we can use the enhanced for-loop statement and its iterator to iterate over ArrayList elements

Java 8+ List interface also provides the forEach(Consumer), internally is an enhanced for-each loop, for your convenient

Using the for loop

List<Integer> lst = new ArrayList<>();  
lst.add(3);  
lst.add(1);  
lst.add(3);

for(int i=0; i<lst.size(); i++){  
    int ele = lst.get(i);
    System.out.println(ele);
}


Using the enhanced for-each loop

List<Integer> lst = new ArrayList<>();  
lst.add(3);  
lst.add(1);  
lst.add(3);

for(int ele : lst){  
    System.out.println(ele);
}


Using the iterator

List<Integer> lst = new ArrayList<>();  
lst.add(3);  
lst.add(1);  
lst.add(3);

Iterator<Integer> iterator = lst.iterator();  
while (iterator.hasNext()){  
    System.out.println(iterator.next());
}


Using Java 8+ forEach(Consumer)

NullPointerException will be thrown if the specified consumer action or the caller list is null

List<Integer> lst = new ArrayList<>();  
lst.add(3);  
lst.add(1);  
lst.add(3);

lst.forEach(System.out::println);  


Conclusion

In this tutorial, we learned some ways to iterate over an ArrayList by using the for loop, for-each loop, iterator and Java 8+ forEach(Consumer)