There are two ways to do this:

  1. A for loop
  2. Using the iterator method.

for loop:

for(x currentX : GetList()) {
    // Do something with the value
}

This is what's called a "for-each" loop, and it's probably the most common/preferred method of doing this. The syntax is:

for(ObjectType variableName : InCollection)

You could also use a standard for loop:

ArrayList<x> list = GetList();
for(int i=0; i<list.size(); i++) {
     x currentX = list.get(i);
     // Do something with the value
 }

The syntax for this is:

for(someStartingValue; doSomethingWithStartingValue; conditionToStopLooping)

iterator method:

Iterator<x> iterator = GetList().iterator();
while(iterator.hasNext()) {
    x currentX = iterator.next();
    // Do something with the value
}
Answer from Caleb Brinkman on Stack Overflow
🌐
Tabnine
tabnine.com › home page › code › java › java.util.arraylist
java.util.ArrayList.iterator java code examples | Tabnine
public Iterator makeEmptyIterator() { ArrayList list = new ArrayList(); return new IteratorChain(list.iterator()); } origin: AltBeacon/android-beacon-library ·
🌐
Blogger
javarevisited.blogspot.com › 2012 › 03 › how-to-loop-arraylist-in-java-code.html
5 Ways to Loop or Iterate over ArrayList in Java?
We can iterate on Java ArrayList using foreach loop introduced in Java 5, by far most clean method until you don't need to remove elements from ArrayList in that case you must use Java Iterator for looping or iterating over ArrayList.
Find elsewhere
🌐
Android Developers
developer.android.com › api reference › arraylist
ArrayList | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
Stack Overflow
stackoverflow.com › questions › 19159403 › how-do-i-implement-a-nested-arraylist-and-iterate-through-them-in-android-java
How do I implement a nested ArrayList and iterate through them in Android Java - Stack Overflow
It's not clear from your question, but if you're trying to decide whether a given Byte segment is in one of the arrays and don't care about iterating over them, it would be cleaner and more efficient to use a Set<Byte> instead of ArrayList<Byte>. Set provides a fast contains() method for this purpose.
🌐
Crunchify
crunchify.com › java j2ee tutorials › how to iterate through java list? seven (7) ways to iterate through loop in java
How to iterate through Java List? Seven (7) ways to Iterate Through Loop in Java • Crunchify
December 28, 2025 - For Loop: 0.014s For Loop Object: 0.218s While Iterator: 0.021s While Loop: 0.01s Stream ForEach: 0.361s ... Instant start = Instant.now(); Instant end = Instant.now(); // create list List crunchifyList = new ArrayList(); for(Long i=0L; i For Loop Example.”); start = Instant.now(); for(int i=0;i Advance For Loop Example..”); start = Instant.now(); for(String temp:crunchifyList){ //System.out.println(temp); } end = Instant.now(); long t2 = Duration.between(start, end).getNano();
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › java arraylist foreach()
Java ArrayList forEach() with Examples - HowToDoInJava
January 12, 2023 - List<String> list = Arrays.asList("A","B","C","D"); list.forEach(System.out::println); A Consumer implementation takes a single argument, and returns no value. We can also pass the custom actions we have created in other places.
🌐
Javatpoint
javatpoint.com › java-arraylist-iterator-method
Java ArrayList Iterator() method with Examples - Javatpoint
Java ArrayList Iterator() method with Examples on add(), addAll(), clear(), clone(), contains(), ensureCapacity(), get(), indexOf(), isEmpty(), iterator(), lastIndexOf(), listIterator(), remove(), removeAll(), subList(), toArray(), trimToSize() etc.
🌐
Mkyong
mkyong.com › home › java › how to loop arraylist in java
How to loop ArrayList in Java - Mkyong.com
August 29, 2012 - #1 normal for loop Text 1 Text 2 Text 3 #2 advance for loop Text 1 Text 2 Text 3 #3 while loop Text 1 Text 2 Text 3 #4 iterator Text 1 Text 2 Text 3 · Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities. ... Thank you Kong, there was No nonsense as stated in start. Straight forward and clear cut examples, but i have 1 question as i am a beginner . why we write List but initialize it as ArrayList,
🌐
Programiz
programiz.com › java-programming › examples › iterate-over-arraylist
Java Program to Iterate over an ArrayList
In the above example, we have used the listIterator() method to iterate over the arraylist.