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 }
};
Answer from obataku on Stack Overflow
🌐
W3Schools
w3schools.com › java › java_arrays_multi.asp
Java Multi-Dimensional Arrays
Java Examples Java Videos Java ... in a table with rows and columns. To create a two-dimensional array, write each row inside its own curly braces:...
🌐
GeeksforGeeks
geeksforgeeks.org › java › multidimensional-arrays-in-java
Java Multi-Dimensional Arrays - GeeksforGeeks
A multi-dimensional array in Java is an array of arrays that allows data to be stored in tabular form such as rows and columns. It is commonly used to represent matrices, tables, and grids in programs.
Published: May 4, 2026
Discussions

Syntax for creating a two-dimensional array in Java - Stack Overflow
In Java, a two-dimensional array can be declared as the same as a one-dimensional array. More on stackoverflow.com
🌐 stackoverflow.com
Need help in Java specifically 2D Array
Show the code you’ve tried so we can give you hints to point you in the right direction or to help explain any misconceptions you have. More on reddit.com
🌐 r/learnprogramming
8
2
April 25, 2023
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
java - Two-dimensional array of different types - Stack Overflow
I want to create a two-dimensional array in which I want to store records from the database. So lets say that the first is of type int and the second of type String (here I am describing just one r... More on stackoverflow.com
🌐 stackoverflow.com
🌐
HWS Math
math.hws.edu › javanotes › c7 › s6.html
Javanotes 9, Section 7.6 -- Two-dimensional Arrays
All of this extends naturally to three-dimensional, four-dimensional, and even higher-dimensional arrays, but they are not used very often in practice. But before we go any farther, there is a little surprise. Java does not actually have two-dimensional arrays.
🌐
Codecademy
codecademy.com › learn › learn-java › modules › java-two-dimensional-arrays › cheatsheet
Learn Java: Two-Dimensional Arrays Cheatsheet | Codecademy
In Java, 2D arrays are stored as arrays of arrays. Therefore, the way 2D arrays are declared is similar 1D array objects. 2D arrays are declared by defining a data type followed by two sets of square brackets.
🌐
Runestone Academy
runestone.academy › ns › books › published › apcsareview › Array2dBasics › a2dDAS.html
10.3. Declaring 2D Arrays — AP CSA Java Review - Obsolete
To declare a 2D array, specify the type of elements that will be stored in the array, then ([][]) to show that it is a 2D array of that type, then at least one space, and then a name for the array. Note that the declarations below just name the variable and say what type of array it will reference.
🌐
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 - Instead of multi-dimensional arrays being stored as a single, contiguous block of memory, Java treats them as arrays of arrays. This means that each row in a two-dimensional array is an independent array stored separately in memory.
Find elsewhere
🌐
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.
🌐
Medium
medium.com › @AlexanderObregon › understanding-multi-dimensional-arrays-in-java-7ead0c3937dd
Understanding Multi-Dimensional Arrays in Java
February 22, 2025 - In Java, you can declare a multi-dimensional array by specifying the number of dimensions using multiple sets of square brackets. For example, here’s how to declare a 2D array: ... This tells Java that arrayName is a two-dimensional array that will store integers.
🌐
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.
Top answer
1 of 13
888

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];
🌐
Runestone Academy
runestone.academy › ns › books › published › csjava › Unit9-2DArray › a2dSummary.html
9.3. 2D Arrays Summary — CS Java
In this chapter you learned about two dimensional arrays. A two dimensional array stores objects in a 2d table. You can think of it as storing objects in rows and columns, but it actually uses an array of arrays to store the objects as shown below. In this chapter you learned how to declare ...
🌐
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

1 1 1 1 1 1
1 2 2 2 2 1
1 2 3 3 2 1
1 2 3 3 2 1
1 2 2 2 2 1
1 1 1 1 1 1

🌐
Carnegie Mellon University
cs.cmu.edu › ~mrmiller › 15-110 › Handouts › arrays2D.pdf pdf
Two-Dimensional Arrays 15-110 Summer 2010 Margaret Reid-Miller
Two-Dimensional Arrays · • Two-dimensional (2D) arrays are indexed by two · subscripts, one for the row and one for the column. • Example: row col · rating[0][2] = 2! !rating[1][3] = 8! 0 · 1 · 2 · 3 · 0 · 4 · 6 · 2 · 5 · 1 · 7 · 9 · 4 · 8 · 2 ·
🌐
Educative
educative.io › courses › lta › data-structures-coding-interviews-java › two-dimensional-arrays
Understanding Two Dimensional Arrays in Java ...
Learn how to declare, initialize, and use two dimensional arrays in Java, including managing rows, columns, and common pitfalls.
🌐
GeeksforGeeks
geeksforgeeks.org › java › print-2-d-array-matrix-java
Print a 2D Array or Matrix in Java - GeeksforGeeks
August 20, 2026 - A 2D array in Java is an array of arrays that is commonly used to represent a matrix. To print all elements of a 2D array, we can use nested loops or built-in methods from the Arrays class.
🌐
Medium
medium.com › buzz-code › java-8-two-dimensional-array-35542b4ced9
Java 8 | Two Dimensional Array
January 12, 2021 - You can just put one more set of brackets in the one dimensional array declaration, like below. ... Then the first brackets means the number of the rows of the array, and the second one means the columns.
🌐
Reddit
reddit.com › r/learnjava › i am not understanding two dimensional arrays.
r/learnjava on Reddit: I am not understanding two dimensional arrays.
April 2, 2018 -

Hey guys! I made a project last week using one dimensional arrays, and it went easy and I felt proud. Now, I got to two dimensional arrays and it all went south, fast. I will post last weeks code to help anyone understand this ones purpose.

Purpose of this weeks project is to make a lottery of three numbers, if a players numbers match the three drawn numbers, they win. Simple as that. My outputs are horrific looking though, and I am sure I can do this more simply than I am. My outputs look like "Player Number [I@3b6eb2ec:[I@3b6eb2ecPlayer Number [I@3b6eb2ec:[I@1e643fafPlayer Number [I@3b6eb2ec:[I@6e8dacdfPlayer Number [I@3b6eb2ec:[I@7a79be86". I haven't made the if statement to match the drawn numbers to the players numbers yet.

Powerball (Old Good Code): https://pastebin.com/xeGR5pQM

Lottery (Unfinished): https://pastebin.com/hQUhvTRk

🌐
Tutorial Gateway
tutorialgateway.org › two-dimensional-array-in-java
Two Dimensional Array in Java
August 8, 2026 - Two Dimensional Array in Java means Array of Arrays. Java 2d Array or Two Dimensional Array, data stored in rows, columns & to access use index.
🌐
TutorialsPoint
tutorialspoint.com › java_data_structures › java_data_structures_two_dimensional_array.htm
Two Dimensional Arrays
A two dimensional array in Java is represented as an array of one dimensional arrays of the same type. Mostly, it is used to represent a table of values with rows and columns − In short a two-dimensional array contains one dimensional arrays as