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 ]
    
๐ŸŒ
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", ...
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ examples โ€บ print-array
Java Program to Print an Array
It accesses each element in the array and prints using println(). import java.util.Arrays; public class Array { public static void main(String[] args) { int[] array = {1, 2, 3, 4, 5}; System.out.println(Arrays.toString(array)); } }
๐ŸŒ
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 - In this example, we define a string-type array empArray, and initialize it with five employee names. Moreover, we use the for loop to iterate over the entire array and print its content using the print() method: ... Overall, this is the simplest ...
๐ŸŒ
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.
๐ŸŒ
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 - Similar to a for-each loop, we can use the Iterator interface to loop through array elements and print them. Iterator object can be created by invoking the iterator() method on a Collection. That object will be used to iterate over that Collectionโ€™s elements. Here is an example of how we can print an array using the Iterator interface:
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ java โ€บ examples โ€บ print-an-array
Java Program to Print an Array | Vultr Docs
November 26, 2024 - In this example, the for-each loop simplifies iterating through the colors array, printing each color followed by a space. Import the java.util.Arrays and java.util.stream.Stream classes.
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ java collections โ€บ how to print an array in java
How to Print an Array in Java
There are a bunch of different ways to print an array in Java. You can use manual traversals using for loops or opt for any standard library methods to do the same.
Published ย  February 14, 2025
Find elsewhere
๐ŸŒ
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,
๐ŸŒ
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
System.out.println("Print array values in Java 1.4 :" + Arrays.asList(sArray)); System.out.println("Print array values in Java 1.4 :" + Arrays.asList(iArray)); Output: Printing Integer array in Java: [I@15b7986 Printing String array in Java: ...
๐ŸŒ
Medium
medium.com โ€บ @pratiyush1 โ€บ how-to-print-the-content-of-an-array-in-java-eea946f2945c
How to Print the Content of an Array in Java | by Pratiyush | Medium
October 15, 2024 - // Example: Processing a list of customer IDs import java.util.Arrays; final int[] customerIDs = {101, 102, 103, 104, 105}; Arrays.stream(customerIDs).forEach(id -> System.out.print(id + " "));
๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ how do i print the contents of an array object?
r/javahelp on Reddit: How do I print the contents of an array object?
June 16, 2020 -

I'm writing a program which utilizes OOP. The program I am creating is supposed to recruit applicants to a team. In my Team.java, I created a method which is supposed to accept members and add it to the team.

In my main.java, everything seems to be working fine. The addMember method works, however when my program is asked to print all the members on the team, only the latest added member is printed.

I tried using a for-loop to add elements to the array but it doesn't do as I expect it to do. It instead prints some kind of cryptic code, something like "Library.@483403".

Can anyone assist me into find a solution? Thank you!

๐ŸŒ
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"] } }
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-program-to-print-the-elements-of-an-array
Java Program to Print the Elements of an Array - GeeksforGeeks
July 23, 2025 - Step 3: Print out each element of the array. Below is the Java example illustrating the printing elements of an 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.
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ 8 methods to print array in java with detailed code examples
8 Methods To Print Array In Java With Detailed Code Examples
December 31, 2024 - We pass this string representation to System.out.println, which displays the entire array in a readable format: [10, 20, 30, 40, 50]. This approach provides a quick and concise way to display all elements of the array in a structured manner.
๐ŸŒ
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 = {
๐ŸŒ
Java Code Geeks
javacodegeeks.com โ€บ home โ€บ core java
How to Print Array Contents in Java - Java Code Geeks
October 7, 2024 - To print the elements of an array, you need to iterate over it or use utility methods from the Arrays class. Here is a code example that demonstrates how to print the elements of an array using a loop:
๐ŸŒ
Intellipaat
intellipaat.com โ€บ home โ€บ blog โ€บ how to print array in java: methods and examples
How to Print Array in Java: Methods and Examples - Intellipaat
May 25, 2025 - Q6. How to display array elements in Java? Printing array elements in Java simple using a for loop to display all the array elements.