You want to follow the same pattern as before:

for (Type curInstance: CollectionOf<Type>) {
  // use currInstance
}

In this case it would be:

for (Bullet bullet : gunList.get(2).getBullet()) {
   System.out.println(bullet);
}
Answer from unholysampler on Stack Overflow
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › different ways to iterate an arraylist
Different Ways to Iterate an ArrayList
January 12, 2023 - ArrayList<String> namesList = new ArrayList<String>(Arrays.asList( "alex", "brian", "charles") ); int index = 0; while (namesList.size() > index) { System.out.println(namesList.get(index++)); } Java program to iterate through an ArrayList of objects with Java 8 stream API.
🌐
GeeksforGeeks
geeksforgeeks.org › java › iterating-arraylists-java
Iterating over ArrayLists in Java - GeeksforGeeks
import java.util.*; class GFG { // Main driver method public static void main(String[] args) { // Creating and initializing the ArrayList // Declaring object of integer type List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8); // Iterating using for loop for (int i = 0; i < numbers.size(); i++) // Printing and display the elements in ArrayList System.out.print(numbers.get(i) + " "); } } Output ·
Published   January 19, 2026
🌐
Vultr Docs
docs.vultr.com › java › examples › iterate-over-an-arraylist
Java Program to Iterate over an ArrayList | Vultr Docs
November 25, 2024 - The hasNext() method checks if there are more elements, and the next() method returns the next element in the iteration. Use the forEach method introduced in Java 8, combined with a lambda expression for concise and efficient iteration.
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-loop-arraylist-in-java
How to loop ArrayList in Java
One of the easiest way to iterate through an ArrayList is by using for loop: import java.util.ArrayList; public class ArrayListExample { public static void main(String[] args) { ArrayList<String> names = new ArrayList<>(); names.add("Chaitanya"); names.add("Rahul"); names.add("Aditya"); // ...
🌐
TutorialsPoint
tutorialspoint.com › program-to-iterate-over-a-list-using-java-8-lambda
Program to iterate over a List using Java 8 Lambda
ArrayList<String>list = arrayList; System.out.println("Iterating..."); list.stream().forEach(elem -> System.out.println(elem)); ... import java.util.ArrayList; import java.util.List; public class Demo { public static void main(String[] args) { ArrayList<String>arrayList = new ArrayList<String>(); ...
🌐
Runestone Academy
runestone.academy › ns › books › published › csjava › Unit8-ArrayList › topic-8-3-arraylist-loops.html
8.3. Traversing ArrayLists with Loops — CS Java
So if you are going to add or remove items or you need the index, use a regular for loop or a while loop. ... 8-3-4: Assume that nums has been created as an ArrayList object and it initially contains the following Integer values [0, 0, 4, 2, 5, 0, 3, 0]. What will nums contain as a result of ...
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
2 weeks ago - Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress.
🌐
Programiz
programiz.com › java-programming › examples › iterate-over-arraylist
Java Program to Iterate over an ArrayList
Here, we have used the for-each loop to iterate over the ArrayList and print each element. import java.util.ArrayList; import java.util.ListIterator; class Main { public static void main(String[] args) { // Creating an ArrayList ArrayList<Integer> numbers = new ArrayList<>(); numbers.add(1); numbers.add(3); numbers.add(2); System.out.println("ArrayList: " + numbers); // Creating an instance of ListIterator ListIterator<Integer> iterate = numbers.listIterator(); System.out.println("Iterating over ArrayList:"); while(iterate.hasNext()) { System.out.print(iterate.next() + ", "); } } }
🌐
Scientech Easy
scientecheasy.com › home › blog › how to iterate arraylist in java
How to Iterate ArrayList in Java - Scientech Easy
May 12, 2025 - In Java programming, ListIterator is used to iterate the elements of array list in both forward as well as backward directions. Using ListIterator, we can also start the iteration from a specific element in the ArrayList.
🌐
Codecademy
codecademy.com › docs › java › arraylist › .foreach()
Java | ArrayList | .forEach() | Codecademy
April 13, 2025 - The .forEach() method performs a specified action on each element of the ArrayList one by one. This method is part of the Java Collections Framework and was introduced in Java 8 as part of the Iterable interface, which ArrayList implements.
🌐
Java67
java67.com › 2012 › 07 › how-to-iterate-loop-traverse-list-java.html
3 Examples to Loop over a List in Java - ArrayList, LinkedList or Vector | Java67
You can check out The Complete Java Masterclass to learn more about the performance benefits provided by lambda expression and stream in Java 8. Here is a sample Java program that demonstrates How to loop through a List in Java in three different ways, Iterator, for-each loop, and traditional for loop. This technique can be used to loop through ArrayList or any other index-based List implementation like Vector.
🌐
TutorialsPoint
tutorialspoint.com › iterate-through-arraylist-in-java
Iterate through ArrayList in Java
July 28, 2025 - In this article, we have learned how to iterate through an ArrayList in Java using different methods such as for loop, while loop, for-each loop, Iterator, and Streams API.
🌐
Blogger
javarevisited.blogspot.com › 2012 › 03 › how-to-loop-arraylist-in-java-code.html
5 Ways to Loop or Iterate over ArrayList 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 them here in more detail.
🌐
JavaGoal
javagoal.com › home › best way to iterate arraylist in java
Best way to iterate ArrayList in Java - JavaGoal
September 5, 2023 - The enhanced for loop and for-each loop are the same, It’s also another good choice for iterating over collections. When should you use Enhanced for loop for ArrayList
🌐
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.
🌐
Netjstech
netjstech.com › 2015 › 08 › how-to-loop-iterate-arraylist-in-java.html
How to Loop or Iterate an Arraylist in Java | Tech Tutorials
Java 8 forEach statement to take advantage of parallel computing using · parallel stream. In that case you need to write it like- cityList.parallelStream().forEach((a)->System.out.println("City Name - " + a)); That's all for this topic How to Loop or Iterate an Arraylist in Java.
🌐
Codecademy
codecademy.com › docs › java › arraylist › .iterator()
Java | ArrayList | .iterator() | Codecademy
August 13, 2024 - The .iterator() method is used to iterate over the elements of a collection (such as an ArrayList) one by one. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!