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
Discussions

string - Java: Iterating through an Array List - Stack Overflow
I have an ArrayList containing names of instantiated objects that I want to execute the method 'count' on. I'm unsure if/how to do that, though. I have a loop to scan through the array list, and ad... More on stackoverflow.com
🌐 stackoverflow.com
Iterating through an arrayList of objects
Well an array list is like an array except it's endless. An array can ONLY hold a limited amount of items you tell it to whereas an array list can hold as many items and constantly grows to hold more items. With that said, you can get stuff from (for example): for (int I = 0; I < arraylist.size(); I++) { if (arraylist.get(i).getId() == 1) { sysout("found!"); } } when you say arraylist.get(i), it's an Employee object- meaning it has all the employee methods (accessors/mutators aka getters/setters). Using an enhanced for each loop is the same thing except no need to say arraylist.get(i) anymore since emp is the same as arraylist.get(i) More on reddit.com
🌐 r/javahelp
6
1
November 7, 2018
java - How to iterate through ArrayList of objects? - Stack Overflow
I have a class called SparseMatrix. It contains an ArrayList of Nodes (also class). I am wondering of how to iterate through the Array and access a value in Node. I have tried the following: //As... More on stackoverflow.com
🌐 stackoverflow.com
April 27, 2017
list - Java how to iterate through an ArrayList of an ArrayList? - Stack Overflow
I am trying to grasp the concept. I have never worked with ArrayLists before (just arrays). What I have is: ArrayList More on stackoverflow.com
🌐 stackoverflow.com
🌐
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
🌐
Programiz
programiz.com › java-programming › examples › iterate-over-arraylist
Java Program to Iterate over an ArrayList
Created with over a decade of experience and thousands of feedback. ... Try Programiz PRO! ... Become a certified Java programmer. Try Programiz PRO! ... import java.util.ArrayList; class Main { public static void main(String[] args) { // Creating an array list ArrayList<String> languages = new ArrayList<>(); languages.add("Java"); languages.add("JavaScript"); languages.add("Python"); System.out.println("ArrayList: " + languages); // Using for loop System.out.println("Iterating over ArrayList using for loop: "); for(int i = 0; i < languages.size(); i++) { System.out.print(languages.get(i)); System.out.print(", "); } } }
🌐
TutorialsPoint
tutorialspoint.com › iterate-through-arraylist-in-java
Iterate through ArrayList in Java
July 28, 2025 - To traverse through the elements of an ArrayList, we can retrieve an iterator object from it using the iterator() method and traverse its elements. In the below example, we will create an ArrayList of Integer type and then iterate over it using an Iterator. import java.util.ArrayList; import ...
🌐
Reddit
reddit.com › r/javahelp › iterating through an arraylist of objects
r/javahelp on Reddit: Iterating through an arrayList of objects
November 7, 2018 -

Hello! I am trying to iterate through an ArrayList and having trouble with getting my loop right. I am trying to use an advanced for loop (the method I figured would be easier for me to understand) to iterate through an arrayList of objects that is some 60,000 records in a database. Basically I need to ask the user for an employee ID and the program is supposed to search the database for it and if it exist then it prints out the info associated to the ID (last name, first name, birthdate). I have all the code right for the database part but I am stuck on getting the program to print the info. I know I need to create the scanner object, the loop, and then somehow use get methods right? Any help would be appreciated!

Here is some of the code I have if it helps:

public static void main(String\[\] args) {
		ArrayList<Employee> emp = getDBData();
		searchEmployee(emp);	
}
	//Search Employee method...
	private static void searchEmployee(ArrayList<Employee> emp) {	
	}
//My arrayList
ArrayList<Employee> set = new ArrayList<Employee>();
//The loop
Scanner scanner = new Scanner(System. in);
		System.out.println("Enter the Employee ID to search: ");
		String empID = scanner.nextLine();	
		for(Employee emp: set){
System.out.println(empID);
		}
Find elsewhere
🌐
Medium
medium.com › @reetesh043 › how-to-iterate-arraylist-in-java-with-examples-c66be52c8211
How to Iterate ArrayList in Java with Examples | by Reetesh Kumar | Medium
January 7, 2024 - Our primary focus will be on iterating through the list in its original order, but we’ll also touch on the straightforward process of traversing it in reverse. Let’s assume we have a simple banking system with a list of bank accounts. Each bank account has a balance, an account number, and a customer’s name. We will use the different Java features to iterate over this list of bank accounts in various ways. import java.util.ArrayList; import java.util.List; public class BankAccount { private int accountNumber; private String customerName; private double balance; public BankAccount(int acc
🌐
W3Schools
w3schools.com › java › java_howto_loop_through_arraylist.asp
Java How To Loop Through an ArrayList
close() delimiter() findInLine() findWithinHorizon() hasNext() hasNextBoolean() hasNextByte() hasNextDouble() hasNextFloat() hasNextInt() hasNextLine() hasNextLong() hasNextShort() locale() next() nextBoolean() nextByte() nextDouble() nextFloat() nextInt() nextLine() nextLong() nextShort() radix() reset() useDelimiter() useLocale() useRadix() Java File Methods Java FileInputStream Java FileOutputStream Java BufferedReader Java BufferedWriter Java Iterator Methods Java Collections Methods Java System Methods Java Errors & Exceptions · Java Examples Java Videos Java Compiler Java Exercises Java
🌐
Blogger
javarevisited.blogspot.com › 2012 › 03 › how-to-loop-arraylist-in-java-code.html
5 Ways to Loop or Iterate over ArrayList in Java?
Best way to iterate over ArrayList is by using advanced for-each loop added in Java 5. I do see value of using Iterator or ListIterator for iterating over ArrayList but only if I want to remote elements from ArrayList during Iteration.
🌐
Vultr Docs
docs.vultr.com › java › examples › iterate-over-an-arraylist
Java Program to Iterate over an ArrayList | Vultr Docs
November 25, 2024 - Obtain an iterator from the ArrayList, and use it to iterate through the elements. This method also allows the removal of elements during iteration which is not safely supported by the other looping constructs.
🌐
Scientech Easy
scientecheasy.com › home › blog › how to iterate arraylist in java
How to Iterate ArrayList in Java - Scientech Easy
May 12, 2025 - The general syntax for Enhanced for loop is as follows: for(data_type element : Object reference variable ) { - - - - - - - - - - - - body - - - - - - } Enhance for loop works in two steps.
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-loop-arraylist-in-java
How to loop ArrayList in Java
One of the limitations with for-each loop is that you cannot remove an element while iterating. An Iterator provides a way to iterate a collection, and it allows you to remove an element while iterating. import java.util.ArrayList; import java.util.Iterator; public class ArrayListExample { public static void main(String[] args) { ArrayList<String> names = new ArrayList<>(); names.add("Chaitanya"); names.add("Rahul"); names.add("Aditya"); Iterator<String> iterator = names.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } } }
🌐
Runestone Academy
runestone.academy › ns › books › published › csjava › Unit8-ArrayList › topic-8-3-arraylist-loops.html
8.3. Traversing ArrayLists with Loops — CS Java
Initialize the allPairs list to an empty ArrayList of WordPair objects. Loop through the words array for the first word in the word pair (for loop from index i = 0 to length-1)
🌐
TutorialsPoint
tutorialspoint.com › loop-through-an-arraylist-using-an-iterator-in-java
Loop through an ArrayList using an Iterator in Java
An Iterator can be used to loop through an ArrayList. The method hasNext( ) returns true if there are more elements in ArrayList and false otherwise. The method next( ) returns the next element in the ArrayList and throws the exception NoSuchElementException if there is no next element.
🌐
Programiz
programiz.com › java-programming › library › arraylist › iterator
Java ArrayList iterator()
import java.util.ArrayList; import java.util.Iterator; class Main { public static void main(String[] args){ ArrayList<String> languages = new ArrayList<>(); // Add elements in the array list languages.add("Java"); languages.add("Python"); languages.add("JavaScript"); languages.add("Swift"); // Create a variable of Iterator // store the iterator returned by iterator() Iterator<String> iterate = languages.iterator(); System.out.println("Element: Index"); // loop through ArrayList till it has all elements // Use methods of Iterator to access elements while(iterate.hasNext()){ // access element String element = iterate.next(); System.out.print(element + ": "); // access index of each element System.out.println(languages.indexOf(element)); } } }
🌐
Coderanch
coderanch.com › t › 673429 › java › iterate-Object-ArrayList
How to iterate through Object ArrayList? (Java in General forum at Coderanch)
This is printed because your class UserData has no overridden toString() method. When you print an object, like this: ... the toString() method will be called on the UserData object, to convert it to text to be displayed on the console. If you don't specify a toString() method yourself in the ...
🌐
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!