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 Top answer 1 of 14
254
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));
2 of 14
35
I would prefer generally foreach when I don't need making arithmetic operations with their indices.
for (int[] x : array)
{
for (int y : x)
{
System.out.print(y + " ");
}
System.out.println();
}
[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
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
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
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
354. Assignment - Printing two dimensional array in tabular ...
09:38
Learn Java 2D arrays in 9 minutes! ⬜ - YouTube
03:16
Java Tutorial Print 2D Array in Grid Format - YouTube
Printing a 2 Dimensional Array (Java Tutorial) - YouTube
Java Tutorial Create 2D Array And Print Individual Elements
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}, ...
Call: +917738666252
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
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
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.
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.