You can print in simple way.

Use below to print 2D array

int[][] array = new int[rows][columns];
System.out.println(Arrays.deepToString(array));

Use below to print 1D array

int[] array = new int[size];
System.out.println(Arrays.toString(array));
Answer from Prabhakaran Ramaswamy on Stack Overflow
Discussions

[Java] Printing out a row in a 2d array
That’s how Java prints arrays. You’ll need to wrap the array in Arrays.toString(array) or alternatively loop over the array printing out results More on reddit.com
🌐 r/learnprogramming
2
1
January 7, 2021
How to print a 2-D array with initial values in a table-like ...
r/javahelp: General subreddit for helping with **Java** code. More on reddit.com
🌐 r/javahelp
Print 2D color array with boxes
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
3
1
June 6, 2021
2D Array Output Help : r/learnjava
For the UI of a 2D point-and-click game, what are the pros and cons of JavaSwing and JavaFX? Are there any other alternatives? Hi all! I am looking to make a 2D point and click game. More on reddit.com
🌐 r/learnjava
🌐
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}, ...
🌐
Baeldung
baeldung.com › home › java › java array › print a java 2d array
Print a Java 2D Array | Baeldung
August 23, 2024 - The most straightforward method involves using nested loops to iterate through the rows and columns of the 2D array. This method is simple and intuitive, making it an excellent choice for basic array printing.
🌐
FavTutor
favtutor.com › blogs › print-2d-array-in-java
Print a 2D Array or Matrix in Java: 4 Easy Methods (with code)
June 16, 2023 - One of the best ways to print a 2D array in Java is to simply convert the array to a string. A 2D array can also be imagined to be a collection of 1D arrays aligned either row-wise or column-wise.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › java tutorial › print 2d array in java
Print 2D Array in Java | Best Methods to Print 2D Array in Java
May 14, 2024 - In the case of the 2D array, the values are stored in a matrix format, which means it is based on row and column index. You can follow any of the below syntaxes for the declaration of an array in java.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
C# Corner
c-sharpcorner.com › article › printing-a-2d-array-in-java-with-code
Printing a 2D Array in Java with Code
January 23, 2025 - public class Print2DArray { public ... row } } } ... Java provides a built-in method called Arrays.deepToString() that can be used to print multi-dimensional arrays easily....
Find elsewhere
🌐
Java2Blog
java2blog.com › home › core java › java array › how to print 2d array in java
How to print 2D array in java | Java2Blog
September 25, 2022 - This is a commonly used method to print the 2D array. ... In Java, we can use the length field to get the length of the array.
🌐
CodeGym
codegym.cc › java blog › java arrays › 2d arrays in java
Java Matrix - 2D Arrays
April 8, 2025 - Here’s another way to print2D arrays in Java using “foreach loop”. This is a special type of loop provided by Java, where the int[]row will loop through each row in the matrix.
🌐
GeeksforGeeks
geeksforgeeks.org › java › simplest-and-best-method-to-print-a-2d-array-in-java
Simplest and Best method to print a 2D Array in Java - GeeksforGeeks
July 12, 2025 - This method helps us to get the String representation of the array. This string can be easily printed with the help of print() or println() method. This is the best and simplest method to print 2D array in Java
🌐
Techie Delight
techiedelight.com › home › java › print two-dimensional arrays in java
Print two-dimensional arrays in Java | Techie Delight
July 7, 2026 - We know that a two-dimensional array in Java is a single-dimensional array having another single-dimensional array as its elements. We can use the Arrays.toString() method to print string representation of each single-dimensional array in the ...
🌐
TutorialsPoint
tutorialspoint.com › print-a-2d-array-or-matrix-in-java
Print a 2D Array or Matrix in Java
September 14, 2023 - For this the logic is to access each element of array one by one and make them print separated by a space and when row get to end in matrix then we will also change the row.
🌐
Medium
alokkumar-17171.medium.com › how-to-print-contents-of-2d-array-properly-without-loop-java-a548d723e396
How to print contents of 2D array properly without loop — Java | by Alok Kumar - Software Engineer - OPEN FOR WORK - | Medium
February 11, 2024 - package com.arrays; import java.util.Arrays; public class SortArray { public static void main(String[] args) { // TODO Auto-generated method stub int[][] arr = {{2, 5, 15},{1, 2, 8},{3, 5, 10},{4,4,20}}; Arrays.sort(arr,(x,y)->{ if(x[1]==y[1]) return x[2]-y[2]; return x[1]-y[1]; }); // Output - [[1, 2, 8], [4, 4, 20], [3, 5, 10], [2, 5, 15]] System.out.println(Arrays.deepToString(arr)); // Output - [[I@6ff3c5b5 System.out.println(arr); } } The above issue occurs not only with 2D array but also with normal array. ... package com.arrays; import java.util.Arrays; public class Print1DArray { public static void main(String[] args) { // TODO Auto-generated method stub int[] arr = {34,12,11,89,42,67}; // Output - [34, 12, 11, 89, 42, 67] System.out.println(Arrays.toString(arr)); // Output - [I@4dc63996 System.out.println(arr); } }
🌐
Reddit
reddit.com › r/learnprogramming › [java] printing out a row in a 2d array
r/learnprogramming on Reddit: [Java] Printing out a row in a 2d array
January 7, 2021 -

Tried printing out the rows in a 2d matrix using this code:

class Main {  
  public static void main(String args[]) { 
    int[][]matrix = { {1,2,3},
                   {4,5,6},
                   {7,8,9},
                   {1,2,1} };
                   
                 
    for(int[] row: matrix){
        System.out.println(row);
    }

  } 
  
}

It doesn't work. I get this on the compiler:

[I@76ed5528
[I@2c7b84de
[I@3fee733d
[I@5acf9800

What's going on?

🌐
IncludeHelp
includehelp.com › java-programs › read-and-print-a-two-dimensional-array.aspx
Java program to read and print a two dimensional array
December 23, 2023 - System.out.print("Enter row for ... scan.nextInt(); // enter array elements. System.out.println("Enter " + (row * col) + " Array Elements : "); for (i = 0; i < row; i++) { for (j = 0; j < col; j++) { arr[i][j] = scan.nextInt(); } } // the 2D array is here....
🌐
GeeksforGeeks
geeksforgeeks.org › java › multidimensional-arrays-in-java
Java Multi-Dimensional Arrays - GeeksforGeeks
... import java.io.*; class Main ... the Array for (int i = 0; i < 2; i++){ for (int j = 0; j < 2; j++) System.out.print(arr[i][j]+" "); System.out.println(); } } }...
Published: May 4, 2026
🌐
Sololearn
sololearn.com › en › Discuss › 2463038 › how-to-print-2-d-elements-in-array-using-while-loop-java
How to print 2 d elements in array using while loop...(java)
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Educative
educative.io › answers › how-to-print-multi-dimensional-arrays-in-java
How to print multi-dimensional arrays in Java
We need to use the number of nested loops to iterate on each item of an N-dimensional array before printing it. As the number of dimensions increases, the code becomes more complex and harder to maintain. However, there is a cleaner approach for this using the Arrays.toString() and Arrays.deepToString() library methods defined within the java.util.Arrays class.
🌐
Medium
medium.com › @amankseth › 2-d-array-in-java-5dc753a41c77
2-D Array Print in Java. Format to print | by Aman Kumar Seth | Medium
September 28, 2024 - But, wait we have something which is called as Arrays.deepToString() method, let’s see how it works: import java.util.Arrays; public class Array2D { public static void main(String[] args) { int[][] arr = { {1, 2, 3}, {4, 5}, {6, 7, 8, 9} }; ...
🌐
Ruby-Doc.org
ruby-doc.org › home › two dimensional array in java – the ultimate guide with examples
Two Dimensional Array in Java - The Ultimate Guide with Examples - Ruby-Doc.org
April 10, 2026 - javaCopyEditpublic class JaggedArrayExample { public static void main(String[] args) { int[][] jagged = new int[3][]; jagged[0] = new int[]{1, 2}; jagged[1] = new int[]{3, 4, 5}; jagged[2] = new int[]{6, 7, 8, 9}; for (int i = 0; i < jagged.length; i++) { for (int j = 0; j < jagged[i].length; j++) { System.out.print(jagged[i][j] + " "); } System.out.println(); } } } ... Index Out of Bounds Exceptions: Always check array lengths before accessing. Assuming uniform row sizes: Java allows jagged arrays, so length of each row might differ. Confusing row and column indices: Remember array[row][column]. Two dimensional arrays in Java are a powerful and flexible way to represent tabular data. Whether for mathematical operations, data storage, or grid-based applications, mastering 2D arrays is essential for Java programmers.