🌐
W3Schools
w3schools.com › java › java_arrays_multi.asp
Java Multi-Dimensional Arrays
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... A multidimensional array is an array that contains other arrays.
🌐
GeeksforGeeks
geeksforgeeks.org › java › multidimensional-arrays-in-java
Java Multi-Dimensional Arrays - GeeksforGeeks
A 2D array represents data in rows and columns. It can be understood as an array of 1D arrays. ... A 2-D array can be seen as a table with 'x' rows and 'y' columns where the row number ranges from 0 to (x-1) and column number ranges from 0 to ...
Published   March 14, 2026
Discussions

Syntax for creating a two-dimensional array in Java - Stack Overflow
Note that in your code only the first line of the 2D array is initialized to 0. Line 2 to 5 don't even exist. More on stackoverflow.com
🌐 stackoverflow.com
I am not understanding two dimensional arrays.
You’re printing the address of the array values. What you want is a string to be printed instead More on reddit.com
🌐 r/learnjava
6
2
April 2, 2018
Can someone ELI5 multidimensional arrays?
to hold every position on a chessboard, you'd use a two-dimensional array board[8][8] More on reddit.com
🌐 r/learnprogramming
11
2
May 30, 2016
How to understand the logic behind two-dimensional arrays?
A 2d array is a coordinate system. Think of it as a finite Cartesian plane with 0,0 at the top left corner. So if you are at (3,5) and want to check the cell above you, then you would check (3,4) because "up" is -1 in the "y" direction. So now let's look at an array specifically. When indexing into a 2d array your first index is the "outer" array which is your "y" coordinate. Then your second index is the "x" coordinate. So to get the value at (3,5) you would write arr[5][3]. Then to get the value of the cell above it you would write arr[4][3]. The "x" direction to the right would be +1 and to the left would be -1. Using that information you can walk around the 2d array as if it's a coordinate system. More on reddit.com
🌐 r/learnprogramming
3
0
January 23, 2019
People also ask

What are common use cases for 2D arrays in Java?
2D arrays are frequently employed for tasks such as representing game boards, matrices in mathematical computations, or organising tabular data in applications.
🌐
pwskills.com
pwskills.com › blog › java developer › 2d array in java: definition, examples, questions
2D Array In Java: Definition, Examples, Questions
Can the size of a 2D array be dynamically changed in Java?
No, the size of a 2D array is generally fixed once declared. To achieve dynamic sizing, you may need to create a new array and copy the elements.
🌐
pwskills.com
pwskills.com › blog › java developer › 2d array in java: definition, examples, questions
2D Array In Java: Definition, Examples, Questions
How do you declare and initialise a 2D array?
To declare a 2D array, specify the data type followed by two sets of square brackets indicating the number of rows and columns. Initialization often involves nested loops.
🌐
pwskills.com
pwskills.com › blog › java developer › 2d array in java: definition, examples, questions
2D Array In Java: Definition, Examples, Questions
🌐
Reddit
reddit.com › r/learnprogramming › need help in java specifically 2d array
r/learnprogramming on Reddit: Need help in Java specifically 2D Array
April 25, 2023 -

I'm creating a program that will sum up the outer squares(1) as well as the inner ones(2)(3).

I've already figured out how to sum up the outer boundaries. But, I can't sum up the inner boundaries.

The current dimension is 6x6 but it also needs to be flexible depending on user preference.

Can anyone help? T.T

111111
122221
123321
123321
122221
111111

🌐
Codecademy
codecademy.com › learn › learn-java › modules › java-two-dimensional-arrays › cheatsheet
Learn Java: Two-Dimensional Arrays Cheatsheet | Codecademy
2D arrays are declared by defining a data type followed by two sets of square brackets. ... In Java, when accessing the element from a 2D array using arr[first][second], the first index can be thought of as the desired row, and the second index ...
🌐
Medium
medium.com › @AlexanderObregon › how-javas-multi-dimensional-arrays-work-for-beginners-faf4f4a9935d
How Java’s Multi-Dimensional Arrays Work for Beginners
February 24, 2025 - This means that each row in a two-dimensional array is an independent array stored separately in memory. In Java, a multi-dimensional array is declared using multiple sets of square brackets:
🌐
Medium
medium.com › @nehud29 › java-2d-arrays-11493587b4be
# JAVA 2D-ARRAYS #. ➤ Advantages of Array in Java | by Neha Das | Medium
June 21, 2024 - # JAVA 2D-ARRAYS # ➤ Advantages of Array in Java • The elements in arrays can be accessed at random using the index number. • Since it generates a single array of several elements, it requires …
Find elsewhere
🌐
Quora
quora.com › What-is-a-two-dimensional-Array-on-Java
What is a two dimensional Array on Java? - Quora
Answer (1 of 3): In Java, two dimensional arrays are actually arrays of arrays. These, as you might expect, look and act like regular multidimensional arrays. However, as you will see, there are a couple of subtle differences.
🌐
PW Skills
pwskills.com › blog › java developer › 2d array in java: definition, examples, questions
2D Array In Java: Definition, Examples, Questions
November 4, 2025 - In Java, a 2D array is a multidimensional array that provides a structured way to organise and store elements in a grid or matrix format. It is essentially an array of arrays, where each element can be accessed using two indices – one for the ...
🌐
Coderanch
coderanch.com › t › 746253 › java › dimensional-arrays
2 dimensional arrays (Java in General forum at Coderanch)
October 9, 2021 - Technically, Java doesn't have a 2D array. What it has is an array of arrays. With this it is possible for each of the rows to have a different number of columns. Practically speaking though, you can design your program if you want so that all rows have the same number of columns, or in effect, ...
🌐
CMU
web2.qatar.cmu.edu › cs › 15121 › notes › 2d-arrays
Two Dimensional Arrays
Remember the Arrays class provided by Java that gave us nice things like Arrays.toString()? It has some additional methods useful for 2D Arrays: If you need to check equality or generate a String from a 2D array, these methods are the best ones to use.
🌐
Runestone Academy
runestone.academy › ns › books › published › csawesome › Unit8-2DArray › topic-8-1-2D-arrays-Day1.html
8.1.1. 2D Arrays (Day 1) — CSAwesome v1
Arrays in Java can store many items of the same type. You can even store items in two-dimensional (2D) arrays which are arrays that have both rows and columns. A row has horizontal elements. A column has vertical elements.
🌐
CodeGym
codegym.cc › java blog › java arrays › 2d arrays in java
Java Matrix - 2D Arrays
April 8, 2025 - A 2D Array takes 2 dimensions, one for the row and one for the column. For example, if you specify an integer array int arr[4][4] then it means the matrix will have 4 rows and 4 columns.
🌐
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
August 5, 2025 - 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.
🌐
Tutorialspoint
tutorialspoint.com › java › java_multi_dimensional_arrays.htm
Java Multi-Dimensional Arrays
Two-dimensional arrays are used to store data in rows and columns, where each row can represent a separate individual array. In short, a two-dimensional array contains one-dimensional arrays of elements.
🌐
Medium
srivastavayushmaan1347.medium.com › understanding-2d-arrays-in-java-a-comprehensive-guide-98b26f206f35
Understanding 2D Arrays in Java: A Comprehensive Guide | by Ayushmaan Srivastav | Medium
October 4, 2023 - To declare a 2D array in Java, you specify both the number of rows and columns. These arrays can be initialized with default values or predefined data.
🌐
Coderanch
coderanch.com › t › 400088 › java › Adding-dimensional-array
Adding to a two-dimensional array (Beginning Java forum at Coderanch)
The array will originally pull its data from a database. In the java API they give an example such as: Object[][] data = { {"Mars Bar", new Integer(2), new Double(23.50)}, {"Mily Way", new Integer(1), new Double(25.00)}, {"Whatever", new Integer(5), new Double(33.67)} }; Ok now when applied this all works fine with the JTable.
🌐
Baeldung
baeldung.com › home › java › java array › jagged arrays in java
Jagged Arrays in Java | Baeldung
July 30, 2025 - Let’s see what a 2D jagged array looks like in memory: Clearly, multiDimensionalArr[0] holds a reference to a single-dimensional array of size 2, multiDimensionalArr[1] holds a reference to another one-dimensional array of size 3, and so on. This way, Java makes it possible for us to define and use jagged multi-dimensional arrays.
Top answer
1 of 13
889

Try the following:

int[][] multi = new int[5][10];

... which is a short hand for something like this:

int[][] multi = new int[5][];
multi[0] = new int[10];
multi[1] = new int[10];
multi[2] = new int[10];
multi[3] = new int[10];
multi[4] = new int[10];

Note that every element will be initialized to the default value for int, 0, so the above are also equivalent to:

int[][] multi = new int[][] {
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};

... or, more succinctly,

int[][] multi = {
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
2 of 13
86

We can declare a two dimensional array and directly store elements at the time of its declaration as:

int marks[][]={{50,60,55,67,70},{62,65,70,70,81},{72,66,77,80,69}};

Here int represents integer type elements stored into the array and the array name is 'marks'. int is the datatype for all the elements represented inside the "{" and "}" braces because an array is a collection of elements having the same data type.

Coming back to our statement written above: each row of elements should be written inside the curly braces. The rows and the elements in each row should be separated by a commas.

Now observe the statement: you can get there are 3 rows and 5 columns, so the JVM creates 3 * 5 = 15 blocks of memory. These blocks can be individually referred ta as:

marks[0][0]  marks[0][1]  marks[0][2]  marks[0][3]  marks[0][4]
marks[1][0]  marks[1][1]  marks[1][2]  marks[1][3]  marks[1][4]
marks[2][0]  marks[2][1]  marks[2][2]  marks[2][3]  marks[2][4]


NOTE:
If you want to store n elements then the array index starts from zero and ends at n-1. Another way of creating a two dimensional array is by declaring the array first and then allotting memory for it by using new operator.

int marks[][];           // declare marks array
marks = new int[3][5];   // allocate memory for storing 15 elements

By combining the above two we can write:

int marks[][] = new int[3][5];
🌐
freeCodeCamp
freecodecamp.org › news › 2d-array-in-java-two-dimensional-and-nested-arrays
2D Array in Java – Two-Dimensional and Nested Arrays
August 10, 2022 - To create a two dimensional array in Java, you have to specify the data type of items to be stored in the array, followed by two square brackets and the name of the array.
🌐
Medium
medium.com › @AlexanderObregon › understanding-multi-dimensional-arrays-in-java-7ead0c3937dd
Understanding Multi-Dimensional Arrays in Java
February 22, 2025 - This tells Java that arrayName is a two-dimensional array that will store integers. The number of square brackets represents the dimensions of the array. If you had a 3D array, it would look like this: ... But for now, let’s focus on 2D arrays, as they are the most common type of multi-dimensional array.