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 ]
    
๐ŸŒ
Team Treehouse
teamtreehouse.com โ€บ community โ€บ print-a-returned-array
Print a returned array (Example) | Treehouse Community
August 5, 2016 - public static int[] createIntArray(int ...(createIntArray(C.length)); } ... When you ask Java to print an array it just prints out the memory address of the array....
Discussions

[Java] Why can't you just print an array with System.out.println(array);
All the other responses are nonsense, the correct answer is simply that the guys who built that class just couldn't be bothered adding those 7 (or whatever) methods necessary to print nicely formatted arrays. Just use Arrays.toString instead. More on reddit.com
๐ŸŒ r/learnprogramming
10
2
May 29, 2017
[JAVA]Console only prints memory address instead of list.

You'll want to either iterate through each element of the array and print it separately, or use Arrays.toString(array) to print the whole thing.

The default toString() method for arrays in java is made to print out a memory address.

See this stackoverflow question: https://stackoverflow.com/questions/409784/whats-the-simplest-way-to-print-a-java-array

More on reddit.com
๐ŸŒ r/learnprogramming
2
0
August 17, 2016
[java] How to access the last element in a two dimensional array of unknown size?
A two dimensional array is just an array of arrays, so to get the last item in the last row, you can get the last array from the first dimension, and get that array's last item: int[] lastRow = array[array.length - 1]; int lastItem = lastRow[lastRow.length - 1]; Or you can get the last row's length, and access the last row & column from the 2D array: int lastRowLength = array[array.length - 1].length; int lastItem = array[array.length - 1][lastRowLength - 1]; or more concisely: int lastItem = array[array.length - 1][array[array.length-1].length - 1]; Edit: typo fixed. thanks to u/HellloWorld More on reddit.com
๐ŸŒ r/learnprogramming
5
0
May 16, 2013
[Java] Needing to output an array via JOptionPane and search the array

If I understand correctly, you want an easier way to concatenate the contents of the array?

Two options that come to mind.

  1. Use a loop, although this will leave an extra space on the end:

    String contents = ""; for (int i = 0; i < ID.length; i++) { contents += ID[i]; contents += " "; }

  2. Even better, use String.join:

    String contents = String.join(" ", ID);

Now for your second issue, it's because you are using == when comparing strings on line 39. Instead, you want to use retID.equals(studentID[x]). See here for an explanation as to why. For the most part, when comparing Objects, you will want to use equals(). == just checks that the memory addresses of the two arguments match.

More on reddit.com
๐ŸŒ r/learnprogramming
2
3
June 9, 2013
๐ŸŒ
JanBask Training
janbasktraining.com โ€บ community โ€บ java โ€บ whats-the-simplest-way-to-print-a-java-array
What\'s the simplest way to print a Java array? | JanBask Training Community
April 29, 2025 - This will neatly print [1, 2, 3, 4, 5]. ... Tip: Always remember to import java.util.Arrays at the top of your file when using toString() or deepToString().
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2024 โ€บ 06 โ€บ how-to-print-2d-array-in-java
How to print 2D Array in Java
June 3, 2024 - You can use Arrays.deepToString() method to print a 2D array. You can simply pass the reference of 2D array as an argument to this method in order to display all the elements. import java.util.Arrays; public class Main { public static void main(String[] args) { int[][] array = { {1, 2, 3}, ...
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
Scaler
scaler.com โ€บ topics โ€บ print-array-in-java
How to Print Array in Java - Scaler Topics
March 13, 2024 - This Java program initializes an array of strings and utilizes the Stream API to iterate through the elements. It invokes the forEach() method to print each element of the array to the console using method reference syntax.
๐ŸŒ
Quora
quora.com โ€บ How-do-you-print-out-all-the-elements-of-the-array-using-a-loop-in-Java
How to print out all the elements of the array using a loop in Java - Quora
Answer (1 of 6): As you have mentioned in your question โ€œall the elements of the arrayโ€, hence i would prefer to use the for each loop in order to traverse through the entire array. My approach is as follow - [code]class ArrayTraverse { public static void main(String args[]) { int my_array[]=...
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ printing-an-array-in-java
Printing an Array in Java: A Guide For Printing to Screen
February 27, 2024 - In conclusion, the best method for printing an array in Java depends on the specific situation. For simple tasks with small arrays, the for-each loop is a good choice. For more complex tasks or large data sets, the Stream API provides more power and flexibility. While printing an array in Java is a straightforward task, you may encounter some common issues.
๐ŸŒ
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 - The loop automatically progresses through all the elements in the array, printing each one on the same line with spaces in between. This method converts the array into a string representation, displaying all elements in a single line. It is concise and works well for 1D arrays. ... import java.util.Arrays; public class PrintArrayToString { public static void main(String[] args) { int[] numbers = {10, 20, 30, 40, 50}; System.out.println(Arrays.toString(numbers)); } }
๐ŸŒ
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. This method takes an array as a parameter and returns a string representation of the array and it can work with all types of arrays like integer ...
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 519357 โ€บ java โ€บ Printing-arrays-ints
Printing arrays of ints (Beginning Java forum at Coderanch)
December 4, 2010 - Try to do one, or both, of the following: 1. Change your loop as follows: This will let you know where you are in the loop as things are printed out. It will shed some light onto what is happening. How many times are you looping? Is this the nubmer of times you are expecting. 2. Try changing the output so you place each array value in a single quote.
๐ŸŒ
OneCompiler
onecompiler.com โ€บ questions โ€บ 3xmsqrrn5 โ€บ -java-how-to-print-an-array-in-human-readable-format
[Java] How to print an array in human readable format? - Questions - OneCompiler
We can use Arrays.toString to print the array in human readable format. import java.util.Arrays; public class JavaArrays { public static void main(String[] args) { String[] colors = { "blue", "red", "green", "yellow" }; System.out.println(colors); System.out.println(Arrays.toString(colors)); } }
๐ŸŒ
Oreate AI
oreateai.com โ€บ blog โ€บ how-to-print-arrays-in-java โ€บ 29ddf33b1bcc74eb2d0b092e9b2a6c29
How to Print Arrays in Java - Oreate AI Blog
January 7, 2026 - Learn effective techniques for printing arrays in Java using loops and built-in utilities like Arrays.toString(), enhancing clarity while coding.
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ java โ€บ programs โ€บ print-array
Print an Array in Java (5 Programs With Output)
October 19, 2025 - Learn how to print arrays in Java using 5 easy methods. Explore simple code examples with output using for loop, for-each, recursion, and more.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ what-s-the-simplest-way-to-print-a-java-array
What's the simplest way to print a Java array?
June 16, 2020 - Generally, to print the contents of an array you need to use for loops, in addition to that you can directly print an array using the toString() method of this class. This method accepts an array as a parameter and returns it in String format. ... import java.util.Arrays; public class ...
๐ŸŒ
AmbitionBox
ambitionbox.com โ€บ interviews โ€บ question โ€บ how-do-you-print-an-array-in-java-N6T0cNsq
How do you print an array in Java?
Prepare for your next job interview with AmbitionBox. Read 12 Lakh+ interview questions & answers shared by real candidates across 1 Lakh+ companies in India.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array
Array - JavaScript | MDN
1 week ago - Array elements are object properties in the same way that toString is a property (to be specific, however, toString() is a method). Nevertheless, trying to access an element of an array as follows throws a syntax error because the property name is not valid: ... JavaScript syntax requires properties beginning with a digit to be accessed using bracket notation instead of dot notation.