To print an ArrayList in Java, you can use several methods depending on your needs:

  • Direct Print Using System.out.println():
    Simply pass the ArrayList directly to System.out.println(). This uses the toString() method of the list and prints elements in a readable format.

    ArrayList<String> list = new ArrayList<>();
    list.add("Apple");
    list.add("Banana");
    System.out.println(list); // Output: [Apple, Banana]
  • Using a For-Each Loop:
    Ideal for printing each element on a new line.

    for (String item : list) {
        System.out.println(item);
    }
  • Using a Traditional For Loop:
    Use get() and size() to iterate by index.

    for (int i = 0; i < list.size(); i++) {
        System.out.println(list.get(i));
    }
  • Using Java 8 Streams (forEach):
    Clean and functional style, especially with lambda expressions.

    list.forEach(System.out::println);
  • Using String.join() (for single-line output):
    Join elements with a delimiter like comma or space.

    System.out.println(String.join(", ", list)); // Output: Apple, Banana
  • Using Collectors.joining() (Java 8+):
    Similar to String.join(), useful in stream pipelines.

    String result = list.stream().collect(Collectors.joining(", "));
    System.out.println(result);

For custom objects, ensure the class overrides toString() to display meaningful output; otherwise, you'll see default hash codes like Object@12345.

list.toString() is good enough.

The interface List does not define a contract for toString(), but the AbstractCollection base class provides a useful implementation that ArrayList inherits.

Answer from oldo on Stack Overflow
🌐
Coderanch
coderanch.com › t › 640499 › java › print-elements-ArrayList
How to print out all the elements inside the ArrayList (Beginning Java forum at Coderanch)
Basically I'm asking how to access all the elements in the ArrayList<Contact> addressBook = new ArrayList<>();?? Here is my source code to help you My main class AddressBook ... First a comment: Be careful adding "print" statements inside of classes methods. They tend not to be exactly what you want.
🌐
Career Karma
careerkarma.com › blog › java › print java arraylist: a complete guide
Print Java ArrayList: A Complete Guide | Career Karma
July 20, 2022 - This method is appropriate for situations where you need to print heterogeneous ArrayLists, or a homogeneous ArrayList made up of a custom class. A single method definition in the class saves you the trouble you would encounter using a for loop. However, this method can seem like overkill in simpler situations. If you have a small list of elements, you can consider going with the for loop method for ease and simplicity in logic. Printing a Java ArrayList is not a straightforward task.
🌐
Educative
educative.io › answers › how-to-print-arraylist-elements-in-java
How to print ArrayList elements in Java
For this, the ArrayList get() method comes to the rescue. Here’s the implementation of the loop: for (int i = 0; i < clients.size(); i++) { System.out.println(clients.get(i)); } Let’s execute it: import java.util.ArrayList; public class CustomerList { public static void main(String[] args) { ArrayList<String> clients = new ArrayList<String>(); // Add clients names to the list ·
🌐
Quora
quora.com › How-do-you-print-elements-of-an-ArrayList-in-Java
How to print elements of an ArrayList in Java - Quora
Answer (1 of 4): There are many, many ways to do this. Let's say you have an instance of an ArrayList (did you declare the variable using the List interface? It's better to do so) called 'list’, with any number of items (where they can be of pretty much any type, depending on the type of items yo...
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-in-java
ArrayList in Java - GeeksforGeeks
Explanation: This program creates an ArrayList of integers, adds elements to it using the add() method, and stores them dynamically. Finally, it prints the elements in insertion order as [1, 2, 3]. It implements List Interface which is a sub-interface of Collection Interface. Java provides ...
Published   October 6, 2016
🌐
LabEx
labex.io › tutorials › java-how-to-print-the-contents-of-an-arraylist-in-java-415157
How to print the contents of an ArrayList in Java | LabEx
Java's ArrayList is a powerful data structure that allows you to store and manipulate collections of elements. In this tutorial, we will explore how to effectively print the contents of an ArrayList in Java, a common task in various programming scenarios.
🌐
Delft Stack
delftstack.com › home › howto › java › print arraylist java
How to Print an ArrayList in Java | Delft Stack
February 2, 2024 - import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<ModelClass> modelList; ModelClass m1 = new ModelClass(); ModelClass m2 = new ModelClass(); ModelClass m3 = new ModelClass(); m1.setName("Sam"); m2.setName("Kevin"); m3.setName("Gwen"); modelList = new ArrayList<ModelClass>(); modelList.add(m1); modelList.add(m2); modelList.add(m3); for (int i = 0; i < modelList.size(); i++) { System.out.println(modelList.get(i).getName()); } } } class ModelClass { private String name; void setName(String name) { this.name = name; } String getName() { return name; } }
Find elsewhere
🌐
Reddit
reddit.com › r/learnjava › why does system.out.println() on an arraylist print out the values instead of the memory location?
r/learnjava on Reddit: Why does System.out.println() on an ArrayList print out the values instead of the memory location?
April 29, 2021 -

If I have the following code:

List<Integer> arr = new ArrayList<>();
arr.add(1);
arr.add(2);
arr.add(3);
System.out.println(arr);

it prints out [1, 2, 3] to the console. Since arr is an object, shouldn't println() print the memory location of the object? Why does it print out each value instead?

🌐
JanbaskTraining
janbasktraining.com › home › java arraylist: what it is & how to create an arraylist in java
Java Print ArrayList String with Example | Arraylist of Objects ...
May 18, 2023 - Here’s an example: import ... colors.add("orange"); colors.add("blue"); colors.add("pink"); // Printing elements System.out.println("colors : " + colors); // Printing the size of ArrayList System.out.println("Number of elements present ...
🌐
Squash
squash.io › how-to-print-arraylist-in-java
How to Print an ArrayList in Java
Then, we use a for-each loop to iterate over the elements and print each element using the System.out.println() method. If you are using Java 8 or a later version, you can use the Stream API to print the elements of an ArrayList.
🌐
Coderanch
coderanch.com › t › 734403 › java › Print-arraylist-items-single-line
Print all arraylist items in one single line. (Java in General forum at Coderanch)
It's returning correct form of values, of course without xxx, but my question is: Shall there be an efficent way to: check Arraylist size, and according size to print items in one row (not in new line.) Ps. no its not working inside the loop. Sout(item.get(i)) it's either printing all items in new line or all items in one single line.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-print-a-collection-in-java
How to Print a Collection in Java? - GeeksforGeeks
July 23, 2025 - Overrider the toString() method in the user-defined class to print the item of the ArrayList in the desired format. Run a for-loop to print the objects. ... // Java Program to print an arraylist of an // user-defined collection import java.util.*; ...
🌐
Java2Blog
java2blog.com › home › core java › java collections › print arraylist in java
Print ArrayList in Java - Java2Blog
October 10, 2023 - Since we are not focusing on ArrayList Introduction, I have kept it straight and simple; if you are interested in learning more about ArrayList, you can refer ArrayList in java. Yes, you read it right! Fortunately, there isn’t a single way to print ArrayList elements.
🌐
Blogger
javahungry.blogspot.com › 2021 › 06 › print-arraylist.html
How to Print ArrayList in Java | Java Hungry
Java 8 gives a new method called forEach method to iterate the elements in the collection objects and Lambda expression to make our code readable and short. In the below code snippet, we have used the forEach() method with a lambda expression to print the String ArrayList object.
🌐
Just Academy
justacademy.co › blog-detail › how-to-print-arraylist-in-java
How to Print ArrayList in Java
Use a for loop to iterate through each element in the ArrayList. Print each element individually using System.out.println(). ... Use Java 8 Streams to easily print the ArrayList elements.
🌐
w3resource
w3resource.com › java-exercises › collection › java-collection-exercise-22.php
Java - Print ArrayList using the position of the elements
Write a Java program to iterate through an ArrayList using a traditional for-loop and print each element’s position and value.
🌐
TutorialKart
tutorialkart.com › java › how-to-print-all-elements-of-an-arraylist-in-java
How to Print all Elements of an ArrayList in Java?
May 4, 2023 - In the following example, we will initialize an ArrayList with some elements and print them using ArrayList.forEach() method. ... import java.util.ArrayList; public class PrintElements { public static void main(String[] args) { ArrayList<String> ...
🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
It is part of the java.util package and implements the List interface. The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified (if you want to add or remove elements to/from an array, you have to create a new one).
🌐
Codingwithharish
codingwithharish.com › posts › print-arraylist-java
How to print Arraylist in Java? | Coding with Harish
You must have printed Arraylist multiple times in your work. But there are few other ways which you might have missed. Let us explore them!!. We can directly pass Arraylist object to System.out.println() to print it’s values