Looping ArrayList in Java or Iteration over ArrayList is very similar to looping Map in Java. In order to loop ArrayList in Java we can use either foreach loop, simple for loop or Java Iterator from ArrayList. We have already touched iterating ArrayList in 10 Example of ArrayList in Java and we will see here in detail. We are going to see examples of all three approaches in this ArrayList tutorial and find out which one is clean and best method of looping arraylist in Java. Before start writing an example for loop in ArrayList let's think why do we need to iterate, traverse or loop an ArrayList if it’s based on index and backed by Array. If we know the index of element than we can directly get that particular element from ArrayList but if you want to print all elements of arraylist and do some operation one by one on each of them, only looping or traversing will help you.
This article is in continuation of my earlier tutorial on ArrayList e.g. How to sort ArrayList in Java on descending order and How to convert Array to ArrayList in Java. If you haven’t read them already then you may find them useful and interesting.