Since Java 5 you can use Arrays.toString(arr) or Arrays.deepToString(arr) for arrays within arrays. Note that the Object[] version calls .toString() on each object in the array. The output is even decorated in the exact way you're asking.

Examples:

  • Simple Array:

    String[] array = new String[] {"John", "Mary", "Bob"};
    System.out.println(Arrays.toString(array));
    

    Output:

    [John, Mary, Bob]
    
  • Nested Array:

    String[][] deepArray = new String[][] {{"John", "Mary"}, {"Alice", "Bob"}};
    // Gives undesired output:
    System.out.println(Arrays.toString(deepArray));
    // Gives the desired output:
    System.out.println(Arrays.deepToString(deepArray));
    

    Output:

    [[Ljava.lang.String;@106d69c, [Ljava.lang.String;@52e922]
    [[John, Mary], [Alice, Bob]]
    
  • double Array:

    double[] doubleArray = { 7.0, 9.0, 5.0, 1.0, 3.0 };
    System.out.println(Arrays.toString(doubleArray));
    

    Output:

    [7.0, 9.0, 5.0, 1.0, 3.0 ]
    
  • int Array:

    int[] intArray = { 7, 9, 5, 1, 3 };
    System.out.println(Arrays.toString(intArray));
    

    Output:

    [7, 9, 5, 1, 3 ]
    
🌐
Software Testing Help
softwaretestinghelp.com › home › java tutorial for beginners: 100+ hands-on java video tutorials › java array – how to print elements of an array in java?
Java Array - How To Print Elements Of An Array In Java
April 1, 2025 - This Tutorial Explains Various Methods to Print Elements of an Array in Java. Methods Covered are - Arrays.toString, For Loop, For Each Loop, & DeepToString
🌐
Stack Overflow
stackoverflow.com › questions › 29610946 › printing-with-java-in-eclipse-for-arrays
printing with java in eclipse for arrays - Stack Overflow
It is working fine with command prompt, but when run on eclipse, the program terminates without displaying the result for a value of ... Please post an MCVE so the behavior can be reproduced. ... I don't really understand what you mean, but first of all add curly brackets to your for loops and give a value to your int num, like this: int num = 1500; int arr[]=new int[num]; for(int i=0;i<num;i++){ arr[i]=i; } for(int i=0;i<num;i++){ System.out.print(arr[i] + " "); }
🌐
Programiz
programiz.com › java-programming › examples › print-array
Java Program to Print an Array
import java.util.Arrays; public class Array { public static void main(String[] args) { int[][] array = {{1, 2}, {3, 4}, {5, 6, 7}}; System.out.println(Arrays.deepToString(array)); } }
🌐
Javatpoint
javatpoint.com › how-to-print-array-in-java
Print Array in Java
How to print array in Java with oops, string, exceptions, multithreading, collections, jdbc, rmi, fundamentals, programs, swing, javafx, io streams, networking, sockets, classes, objects etc,
🌐
The Eclipse Foundation
eclipse.org › forums › index.php › t › 1102801
Eclipse Community Forums: C / C++ IDE (CDT) » Print array in Debugger console | The Eclipse Foundation
The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 350 open source projects, including runtimes, tools and frameworks.
🌐
Blogger
javarevisited.blogspot.com › 2012 › 12 › 3-example-to-print-array-values-in-java.html
3 Examples to Print Array Elements/Values in Java - toString and deepToString from Arrays
As I said there is no direct way to print values of the array in Java if you directly pass primitive or object array to System.out.println() you will receive the following output:
🌐
Java67
java67.com › 2014 › 03 › how-to-print-array-in-java-example-tutorial.html
How to Print Array with elements in Java? [Solution + Example] | Java67
These methods are overloaded, much like System.out.println() method to accept all primitive types, which means a different method is called if you pass a boolean array, and a different one is called when you print integer array.
🌐
Stack Overflow
stackoverflow.com › questions › 34009544 › studio-wont-print-array-elements-when-i-test-java
eclipse - Studio won't print array elements when I test. (Java) - Stack Overflow
In the first iteration (y=0, z=0) of the nested for-loops this empty element gets printed two times. Try adding inputDevice.nextLine() after each nextInt() call and you will see that it is working ;) And PLEASE: Don't name variables uppercase! import java.util.Scanner; public class FavoriteListMaker { public static void main(String[] args) { Scanner inputDevice = new Scanner(System.in); System.out.println("This program is to help you order a favorites list.
Find elsewhere
🌐
Mkyong
mkyong.com › home › java › how to print an array in java
How to print an Array in Java - Mkyong.com
October 18, 2021 - The below example uses the Collectors.joining to join arrays into a string and print it out. ... package com.mkyong; import java.util.Arrays; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; public class PrintArray3 { public static void main(String[] args) { // simple array String[] strArray = new String[]{"Java", "Node", "Python", "Ruby"}; String strArrayCollect = Arrays.stream(strArray).collect(Collectors.joining(", ")); System.out.println(strArrayCollect); // alternative System.out.println(String.join(", ", strArray)); int[] intArray = {
🌐
Javadevnotes
javadevnotes.com › java-print-array-examples
Java Print Array Examples - JavaDevNotes
The resulting String is passed to the println method to display on the screen. The output is below. Notice the square brackets on the output, in addition to the elements separated with commas. ... The Arrays.toString() method can't be used with a arrays with dimension two or greater. Here is a simple illustration, this code: import java.util.Arrays; /** * A Simple Program That Prints An Array In Java using Arrays.toString().
🌐
GeeksforGeeks
geeksforgeeks.org › java › simplest-method-to-print-array-in-java
Simplest Method to Print Array in Java - GeeksforGeeks
July 23, 2025 - Arrays.toString() Method of java.util.Arrays class is the simplest method to print an array in Java.
🌐
Sentry
sentry.io › sentry answers › java › print an array in java
Print an array in Java | Sentry
import java.util.Arrays; class Main { public static void main(String[] args) { String[] products = new String[]{"Coffee", "Tea", "Chocolate Bar"}; System.out.println(Arrays.toString(products)); // will print ["Coffee", "Tea", "Chocolate Bar"] } }
🌐
Baeldung
baeldung.com › home › java › java array › how to print the content of an array in java
How to Print the Content of an Array in Java | Baeldung
September 5, 2024 - The output shows that the for-each ... errors and ensuring type safety. The Java Arrays class provides a static method named toString() that can be used to print the array content....
🌐
The Eclipse Foundation
eclipse.org › forums › index.php
Eclipse Community Forums: Newcomers » Better way to print arrays? | The Eclipse Foundation
The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 350 open source projects, including runtimes, tools and frameworks.
🌐
javaspring
javaspring.net › blog › how-to-print-or-return-an-array-in-java
How to Print or Return an Array in Java — javaspring.net
In this example, the for loop iterates over each element of the numbers array and prints it to the console. The Arrays class in Java provides a convenient method called toString() that can be used to print an array in a more readable format.