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
🌐
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. Helps store and manage data in multiple dimensions (rows and columns). Most commonly used type is the two-dimensional (2D) array. ... public class Geeks { public static void main(String[] args) { // Declaring a 2D array int[][] arr; // Initializing row and column sizes arr = new int[1][3]; // Assigning values arr[0][0] = 3; arr[0][1] = 5; arr[0][2] = 7; // Displaying values System.out.println("arr[0][0] = " + arr[0][0]); System.out.println("arr[0][1] = " + arr[0][1]); System.out.println("arr[0][2] = " + arr[0][2]); } }
Published: May 4, 2026
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];
🌐
GeeksforGeeks
geeksforgeeks.org › java › different-ways-to-declare-and-initialize-2-d-array-in-java
Different Ways To Declare And Initialize 2-D Array in Java - GeeksforGeeks
July 23, 2025 - Note: We can write [ ][ ] after data_type or we can write [ ][ ] after array_name while declaring the 2D array. data_type[][] array_Name = new data_type[row][col]; The total elements in any 2D array will be equal to (row) * (col).
🌐
Runestone Academy
runestone.academy › ns › books › published › apcsareview › Array2dBasics › a2dDAS.html
10.3. Declaring 2D Arrays — AP CSA Java Review - Obsolete
To create an array use the new keyword, followed by a space, then the type, and then the number of rows in square brackets followed by the number of columns in square brackets, like this new int[numRows][numCols]. The number of elements in a 2D array is the number of rows times the number of ...
🌐
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 ...
🌐
W3Schools
w3schools.com › java › java_arrays_multi.asp
Java Multi-Dimensional Arrays
A multidimensional array is an array that contains other arrays.
🌐
Java67
java67.com › 2014 › 10 › how-to-create-and-initialize-two-dimensional-array-java-example.html
How to declare and Initialize two dimensional Array in Java with Example | Java67
Ye you can. A 2D array is an array of arrays. Those arrays don't have to be of the same length.Delete ... You can declare 2 dimensional array where each sub array is of different length because its not mandatory to specify length of second dimension while declaring 2D array in Java.
🌐
Blogger
javarevisited.blogspot.com › 2016 › 02 › 6-example-to-declare-two-dimensional-array-in-java.html
6 ways to declare and initialize a two-dimensional (2D) String and Integer Array in Java - Example Tutorial
June 28, 2025 - Now, let's see a couple of ways to declare a two-dimensional array in Java to understand the concept better. As far as Java is concerned, you should always remember that there is nothing like a two-dimensional array, in fact, it's just an array of a one-dimensional array. This is the key to writing an algorithm involving multi-dimensional arrays like looping through a 2D array, searching elements, etc.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › two dimensional array in java
Two Dimensional Array In Java with Examples - Scaler Topics
June 8, 2024 - Since a 2D array in Java consists of rows and columns, we need two indices, one to refer to rows and the other to a particular column in that row. Hence, the syntax of declaring a two-dimensional array is similar to that of a one-dimensional array, with the exception of having two square brackets instead of one:
🌐
EDUCBA
educba.com › home › software development › software development tutorials › java tutorial › 2d arrays in java
2D Arrays in Java | A Comprehensive Guide and Examples
September 29, 2023 - Here is an explanation of the procedure ... declaring a 2D array: ... To initiate a fresh 2D array, utilize the “new” keyword together with the dimensions of the Array:...
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
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.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › two-dimensional array in java
Two-Dimensional Array in Java | Syntax & Example Program
July 22, 2026 - Check out upGrad’s Software ... can declare a two-dimensional array by specifying the data type, followed by the array name and the size of each dimension within square brackets....
🌐
Medium
medium.com › @AlexanderObregon › understanding-multi-dimensional-arrays-in-java-7ead0c3937dd
Understanding Multi-Dimensional Arrays in Java
February 22, 2025 - Let’s break this down step by step to help you understand how multi-dimensional arrays work in Java. In Java, you can declare a multi-dimensional array by specifying the number of dimensions using multiple sets of square brackets.
🌐
Runestone Academy
runestone.academy › ns › books › published › csjava › Unit9-2DArray › a2dSummary.html
9.3. 2D Arrays Summary — CS Java
You can access an item (element) at a given row and column index. 2d Array Declaration - To declare an 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.
🌐
Hero Vired
herovired.com › learning-hub › topics › two-dimensional-array-in-java
Two-Dimensional Array in Java - Hero Vired
July 29, 2024 - In the above syntax, we are declaring two array objects m and mb, where m represents a one-dimensional integer array and mb represents a two-dimensional integer array. ... 4. 2D Array with Variable Column Length: In Java, we can declare a two-dimensional array with a variable column length using the given syntax.
🌐
Tutorial Gateway
tutorialgateway.org › two-dimensional-array-in-java
Two Dimensional Array in Java
April 5, 2016 - Here, we used double as the data type to declare a two dimensional array in Java.
🌐
Smartprogramming
smartprogramming.in › tutorials › java › multi-dimensional-array-2d
Multi-Dimensional Array (2D) in Java with Examples
This is done using the new keyword in Java. At this stage, a fixed block of memory is reserved to store multiple elements of the specified data type. The size of the array must be defined during creation (it cannot be changed later). ... NOTE : We can declare and create a 2D array in a single ...
🌐
Dyclassroom
dyclassroom.com › java › java-two-dimensional-arrays
Java - Two Dimensional Arrays - Java - dyclassroom | Have fun learning :-)
To create a 2D array we use the new keyword as shown below. ... Where, arrayName is the name of the array variable of data type dataType and it has row_size number of rows and col_size number of columns.
🌐
Medium
medium.com › @iamprem021 › a-simple-guide-to-2d-arrays-in-java-4f5f5e5e1a96
A Simple Guide to 2D Arrays in Java | by premprakash | Medium
May 24, 2024 - A 2D array in Java is an array of arrays. Think of it like a table with rows and columns, where each cell holds a value. It’s like a grid or matrix that can store data in a more organized way. Here’s how you can declare and initialize a 2D array in Java:
🌐
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
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.