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 ]
    
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_arrays.asp
Java Arrays
Java Wrapper Classes Java Generics Java Annotations Java RegEx Java Threads Java Lambda Java Advanced Sorting ... How Tos Add Two Numbers Swap Two Variables Even or Odd Number Reverse a Number Positive or Negative Square Root Area of Rectangle Celsius to Fahrenheit Sum of Digits Check Armstrong Num Random Number Count Words Count Vowels in a String Remove Vowels Count Digits in a String Reverse a String Palindrome Check Check Anagram Convert String to Array Remove Whitespace Count Character Frequency Sum of Array Elements Find Array Average Sort an Array Find Smallest Element Find Largest Element Second Largest Array Min and Max Array Merge Two Arrays Remove Duplicates Find Duplicates Shuffle an Array Factorial of a Number Fibonacci Sequence Find GCD Check Prime Number ArrayList Loop HashMap Loop Loop Through an Enum
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ examples โ€บ print-array
Java Program to Print an Array
Become a certified Java programmer. Try Programiz PRO! ... public class Array { public static void main(String[] args) { int[] array = {1, 2, 3, 4, 5}; for (int element: array) { System.out.println(element); } } }
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ simplest-method-to-print-array-in-java
Simplest Method to Print Array in Java - GeeksforGeeks
July 23, 2025 - ... // Java Program to print the elements // using Arrays.toString() Method import java.util.Arrays; public class GFG { public static void main(String[] args) { // integer array int[] a = { 1, 2, 3, 4, 5 }; // string array String[] s = { "vivek", ...
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_arrays_loop.asp
Java Loop Through an Array
You can loop through the array elements with the for loop, and use the length property to specify how many times the loop should run. This example creates an array of strings and then uses a for loop to print each element, one by one:
๐ŸŒ
W3Schools
w3schools.in โ€บ java โ€บ arrays
Java Arrays - W3Schools
public class Sample { public static void main(String args[]) { int[] newArray = new int[5]; // Initializing elements of array seperately for (int n = 0; n < newArray.length; n++) { newArray[n] = n; } System.out.println(newArray[2]); // Assigning 2nd element of array value } }
๐ŸŒ
W3Schools Blog
w3schools.blog โ€บ home โ€บ arrays in java
Arrays in Java - W3schools
January 19, 2020 - We can get the name of dynamically ... arrayClassName = arrayClass.getName(); //Print array class name System.out.println("Array class name: " + arrayClassName); } }...
๐ŸŒ
w3resource
w3resource.com โ€บ java-exercises โ€บ array โ€บ index.php
Java Array exercises: Array Exercises - w3resource
Example: Input : nums1= { 1, 2, -2, 3, 4, 5, 6 } nums2 = { 1, 2, 3, 4, 5, 6 } nums3 = { 1, 2, -3, 4, 5, 6 } Output: Does the said array contain a subarray with 0 sum: true Does the said array contain a subarray with 0 sum: false Does the said array contain a subarray with 0 sum: true ... Write a Java program to print all sub-arrays with 0 sum present in a given array of integers.
Find elsewhere
๐ŸŒ
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"] } }
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_variables_print.asp
Java Print/Display Variables
Java Wrapper Classes Java Generics Java Annotations Java RegEx Java Threads Java Lambda Java Advanced Sorting ... How Tos Add Two Numbers Swap Two Variables Even or Odd Number Reverse a Number Positive or Negative Square Root Area of Rectangle Celsius to Fahrenheit Sum of Digits Check Armstrong Num Random Number Count Words Count Vowels in a String Remove Vowels Count Digits in a String Reverse a String Palindrome Check Check Anagram Convert String to Array Remove Whitespace Count Character Frequency Sum of Array Elements Find Array Average Sort an Array Find Smallest Element Find Largest Element Second Largest Array Min and Max Array Merge Two Arrays Remove Duplicates Find Duplicates Shuffle an Array Factorial of a Number Fibonacci Sequence Find GCD Check Prime Number ArrayList Loop HashMap Loop Loop Through an Enum
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ java-array-methods-how-to-print-an-array-in-java
Java Array Methods โ€“ How to Print an Array in Java
July 20, 2020 - In Java, arrays are objects. All methods of class object may be invoked in an array. We can store a fixed number of elements in an array. ... The System.out.println() method converts the object we passed into a string by calling String.valueOf() .
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_output.asp
Java Output Values / Print Text
Java Wrapper Classes Java Generics Java Annotations Java RegEx Java Threads Java Lambda Java Advanced Sorting ... How Tos Add Two Numbers Swap Two Variables Even or Odd Number Reverse a Number Positive or Negative Square Root Area of Rectangle Celsius to Fahrenheit Sum of Digits Check Armstrong Num Random Number Count Words Count Vowels in a String Remove Vowels Count Digits in a String Reverse a String Palindrome Check Check Anagram Convert String to Array Remove Whitespace Count Character Frequency Sum of Array Elements Find Array Average Sort an Array Find Smallest Element Find Largest Element Second Largest Array Min and Max Array Merge Two Arrays Remove Duplicates Find Duplicates Shuffle an Array Factorial of a Number Fibonacci Sequence Find GCD Check Prime Number ArrayList Loop HashMap Loop Loop Through an Enum
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ java collections โ€บ how to print an array in java
How to Print an Array in Java
Months of the year are as follows: January February March April May June July August September October November December To reinforce what you learned, we suggest you watch a video lesson from our Java Course ยท Youโ€™ve already got the hang of printing simple arrays using methods like Arrays.toString(), but things get trickier with multi-dimensional arrays.
Published ย  February 14, 2025
๐ŸŒ
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....
๐ŸŒ
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.
๐ŸŒ
UpStack
upstackhq.com โ€บ upstack blog โ€บ software development
How To Print An Array In Java | Upstack
This is by far the easiest way to print or iterate through an array in any programming language; when asked to print an array as a programmer, the first thing you must do is start writing the loop. You can use for loop to iterate over the elements of the array. Below is a program that demonstrates the use of "for" loops in Java.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ how-to-print-an-array-in-java
How to Print an Array in Java
February 24, 2023 - From there, we used streams so that we can quickly print array elements line by line. We've also covered how to convert an array to a list, which you can either just call or use the Java 8 Stream API for more granular control.
๐ŸŒ
Java Code Geeks
javacodegeeks.com โ€บ home โ€บ core java
How to Print Array Contents in Java - Java Code Geeks
October 7, 2024 - System.out.println() โ€“ This prints the string representation of the array. The code produces the following output in the IDE console: ... Multi-dimensional arrays, such as two-dimensional arrays, can be thought of as arrays of arrays.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ java โ€บ examples โ€บ print-an-array
Java Program to Print an Array | Vultr Docs
November 26, 2024 - Arrays can hold primitives (like int, char, etc.) or objects (like Strings or other Java objects). In this article, you will learn how to print arrays in Java using different methods. Explore practical examples that include using loops, Java 8 Streams, and the Arrays utility class.