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
🌐
GeeksforGeeks
geeksforgeeks.org › java › print-2-d-array-matrix-java
Print a 2D Array or Matrix in Java - GeeksforGeeks
March 24, 2025 - // Java program to print the elements of // a 2 D array or matrix using toString() import java.io.*; import java.util.*; // Driver Class class Geeks { public static void print2D(int mat[][]) { // Loop through all rows for (int[] row : mat) // converting each row as string // and then printing in a separate line System.out.println(Arrays.toString(row)); } public static void main(String args[]) throws IOException { int mat[][] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }; print2D(mat); } } ... Example 4: Using Arrays.deepToString(int[][]) converts the 2D array to a string in a single
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
java - Printing a 2D array - Code Review Stack Exchange
I finished this program to print a 2D array. I got the right output, but I'm not sure if I did what was being asked in the problem below. Can someone please look at the question below and tell me if I miss any part of the question? The part where I got confused was when it said to read in the size of each dimension: package twoDarray; import java... More on codereview.stackexchange.com
🌐 codereview.stackexchange.com
October 11, 2012
How to print a 2-D array with initial values in a table-like ...
🌐 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
🌐
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.
🌐
W3Schools
w3schools.com › java › java_arrays_multi.asp
Java Multi-Dimensional 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
🌐
Codecademy
codecademy.com › learn › learn-java › modules › java-two-dimensional-arrays › cheatsheet
Learn Java: Two-Dimensional Arrays Cheatsheet | Codecademy
//Given a 2d array called `arr` which stores `int` values ... In Java, initializer lists can be used to quickly give initial values to 2D arrays.
🌐
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
🌐
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}, ...
🌐
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); } }
🌐
Coderanch
coderanch.com › t › 650514 › java › Printing-Array-String-specific-format
Printing a 2d Array to String in specific format (Beginning Java forum at Coderanch)
May 27, 2015 - Don't call the String array; that is very confusing. Don't call the parameter m. That is a dreadful name. Why are you using System.out. when your method says it returns a String? Make the method return the String and do nothing else, least of all printing. You can always test it with System.out.println(MyArrayClass.toString(myArray)); Why are you using for loops when you can use for‑each loops?
🌐
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.
🌐
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 - In 2D arrays, arr.length returns the number of rows it has, and performing the same operation on any one of its indices (for example arr[0].length) will return the number of columns in the array. It’s great that now you know how to print matrices in Java, now you should also learn sorting algorithms in Java.
🌐
Quora
quora.com › How-do-I-print-the-most-common-digit-in-a-2D-array-using-Java
How to print the most common digit in a 2D array using Java - Quora
Answer (1 of 4): How would you do it be hand? Pick a small array, 5x5 is large enough, and figure out what you would do to figure it out by hand. What would you keep track of? How would you know which digit to print? There are a whole lot of programming problems that are that easy (or that hard ...
🌐
LeetCode
leetcode.com › problems › transpose-matrix
Transpose Matrix - LeetCode
Can you solve this real interview question? Transpose Matrix - Given a 2D integer array matrix, return the transpose of matrix. The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices. [https://assets.leetcode.com/uploads/2021/02/10/hint_transpose.png] Example 1: Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [[1,4,7],[2,5,8],[3,6,9]] Example 2: Input: matrix = [[1,2,3],[4,5,6]] Output: [[1,4],[2,5],[3,6]] Constraints: * m == matrix.length * n == matrix[i].length * 1
🌐
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} }; ...
🌐
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.
🌐
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?

🌐
W3Schools
w3schools.com › python › numpy › numpy_array_indexing.asp
NumPy Array Indexing
import numpy as np arr = np.array([[1,2,3,4,5], [6,7,8,9,10]]) print('Last element from 2nd dim: ', arr[1, -1]) Try it Yourself » ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
C# Corner
c-sharpcorner.com › article › 2d-array-take-input-and-print-output-same
2D array - Take Input and Print Output Same
May 10, 2024 - import java.util.*; // Online Java Compiler // Use this editor to write, compile and run your Java code online public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int n = scn.nextInt(); int m = scn.nextInt(); int [][] mat = new int [n] [m]; // System.out.println("rows " + mat.length); // System.out.println("column "+ mat[0].length); for (int i =0; i <n; i++) { for (int j =0; j < m ; j++) { mat[i][j]= scn.nextInt(); } // System.out.println(); } for(int i =0; i <n ; i++) { for (int j =0; j < m; j++) { System.out.print(mat[i][j]+" "); } System.out.println(); } } } Reading dimensions of the 2D array. int n = scn.nextInt(); int m = scn.nextInt(); These lines use the nextInt () method of the Scanner class to read two integers entered by the user, which represent the number of rows (n) and the number of columns (m) of the 2D array, respectively.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › introduction-to-arrays-data-structure-and-algorithm-tutorials
Array Introduction - GeeksforGeeks
February 16, 2026 - Java · // Fixed sized array examples int[] arr1 = new int [5]; // Another way (Array creation and // initialization both) int[] arr2 = {1, 2, 3, 4, 5}; Python · # Create a fixed-size list of length 5, # initialized with zeros arr = [0] * 5 # Output the fixed-size list print(arr) C# // Fixed sized array examples int[] arr1 = new int [5]; // Another way (Array creation and // initialization both) int[] arr2 = {1, 2, 3, 4, 5}; 2.