How to Print a List in Java
System.out.println(list) prints a Java list's elements between square brackets, separated by a comma and a space: [customer, beta-tester]. The same text appears when you join a list to a string with +, because both use the list's toString.
Syntax
System.out.println(list);
System.out.println("text" + list);
| Part | What it does |
|---|---|
System.out.println(list) | Prints the list's toString: its elements between square brackets, separated by , . |
"text" + list | Joins the text and the list's toString into one string. |
list | Any list, such as one made with List.of. |
The format comes from toString, which the lists in this post inherit from AbstractCollection: "The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String.valueOf(Object)."
The Example
The example prints a list of strings, the same list after some text, a list of numbers and an empty list.
Prerequisites
- A JDK 11 or later, which can run a single
.javafile directly. This guide uses OpenJDK 25.0.5.1.
Step 1: Write the Code
Create a file named Main.java:

import java.util.List;
public class Main {
public static void main(String[] args) {
List<String> roles = List.of("customer", "beta-tester");
List<Integer> limits = List.of(10, 500);
System.out.println(roles);
System.out.println("roles: " + roles);
System.out.println(limits);
System.out.println(List.of());
}
}
Step 2: Run It
java Main.java
[customer, beta-tester]
roles: [customer, beta-tester]
[10, 500]
[]

java Main.java compiles the file in memory and runs it. The command is the same in zsh, bash and PowerShell.
What Happened
println(roles)printed[customer, beta-tester]: the elements in order, between square brackets, with,between them. The strings print without quotes."roles: " + rolesprinted the same list afterroles:. Joining a list to a string with+uses the sametoString.println(limits)printed[10, 500]. Numbers print the same way.println(List.of())printed[], an empty pair of brackets.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Printing an array instead of a list | Something like [Ljava.lang.String;@1cab0bfb: the array's type and a number, not its elements | Use Arrays.toString(array), which printed [customer, beta-tester] |
Printing a list of objects whose class has no toString | Something like [Main$Plan@76329302] | Give the class a toString, or make it a record: a record printed [Plan[name=pro, limit=500]] |
Using String.join on a list of numbers | error: no suitable method found for join(String,List<Integer>) | Use String.join for strings only, and print other lists as they are |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
[Ljava.lang.String;@ followed by letters and digits | An array was printed, not a list | Use Arrays.toString |
A class name, @ and a number inside the brackets, such as Main$Plan@76329302 | The elements' class doesn't have its own toString | Add a toString, or make the class a record |
error: no suitable method found for join(String,List<Integer>) | String.join was given a list that isn't text | Print the list with println |
FAQ
How do I print a list without the brackets?
For a list of strings, use String.join: String.join(", ", roles) printed customer, beta-tester.
How are null and nested lists printed?
Each element prints as its own toString, and null as the word null. A list holding "a", null, a list of 1 and 2, and a map printed [a, null, [1, 2], {k=v}].
Conclusion
System.out.println(list) prints a list's elements between square brackets, separated by commas, and "text" + list gives the same text after your own. Arrays and classes without a toString don't print that way, so use Arrays.toString for an array, and give your own classes a toString.
Additional Resources
- AbstractCollection.toString, in the Java 25 API documentation.
