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
Then create a nested loop to take input from user to add element in the multi-dimensional array. Then print the multi-dimensional array and close the scanner object. Example: Java program to demonstrate how to create Two Dimensional Array with User input.
Published   May 4, 2026
🌐
Scaler
scaler.com › home › topics › two dimensional array in java
Two Dimensional Array In Java with Examples - Scaler Topics
June 8, 2024 - Hence, in Java, a two-dimensional array is a collection of pointers, where each pointer refers to a one-dimensional array that represents a particular row of the 2D array. 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 ...
People also ask

What is a two-dimensional array in Java?
A two-dimensional array in Java is an array of arrays that stores data in rows and columns. It’s ideal for representing matrices, tables, and grid-like structures in both programming logic and data storage. A two-dimensional array in Java is an array of arrays that stores data in rows and columns. It’s ideal for representing matrices, tables, and grid-like structures in both programming logic and data storage.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › two-dimensional array in java
Two-Dimensional Array in Java | Syntax & Example Program
What is a simple two-dimensional array program in Java?
A basic 2D array program in Java creates an array, assigns values, and prints them using nested loops. It’s a foundational exercise in understanding array structures and indexing. A basic 2D array program in Java creates an array, assigns values, and prints them using nested loops. It’s a foundational exercise in understanding array structures and indexing.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › two-dimensional array in java
Two-Dimensional Array in Java | Syntax & Example Program
How do you create and initialize a two-dimensional array in Java?
To create a two-dimensional array in Java, use int[][] arr = new int[3][4]; for a 3-row, 4-column structure. You can also initialize values directly using nested curly braces. To create a two-dimensional array in Java , use int[][] arr = new int[3][4]; for a 3-row, 4-column structure. You can also initialize values directly using nested curly braces.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › two-dimensional array in java
Two-Dimensional Array in Java | Syntax & Example Program
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];
🌐
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:...
🌐
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.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › two-dimensional array in java
Two-Dimensional Array in Java | Syntax & Example Program
September 2, 2025 - In Java, you 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. ... Strengthen your foundation in object-oriented programming and advance your career ...
🌐
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.
Find elsewhere
🌐
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 - 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.
🌐
Hero Vired
herovired.com › learning-hub › topics › two-dimensional-array-in-java
Two-Dimensional Array in Java - Hero Vired
July 29, 2024 - To declare a two-dimensional array in Java, You specify the data type of the elements followed by two sets of square brackets ‘[]’. For example, ... The above syntax only declares a dimensional array in Java; memory is allocated for the array object, but values will be added later.
🌐
Tutorialspoint
tutorialspoint.com › java › java_multi_dimensional_arrays.htm
Java Multi-Dimensional Arrays
In Java, we can initialize the values of a two-dimensional array by specifying the indexing of the elements, i.e, the row index and column index of the 2D array. The following is the syntax for initializing the value of a 2D array by indexing:
🌐
Scientech Easy
scientecheasy.com › home › blog › multidimensional array in java (2d array)
Multidimensional Array in Java (2D Array) - Scientech Easy
February 14, 2025 - There are mainly two ways to create a two-dimensional array in java that are as follows: 1. The syntax to create a two dimensional array and directly store elements at the time of its declaration, as follows:
🌐
Dremendo
dremendo.com › java-programming-tutorial › java-two-dimensional-array
Two Dimensional Array in Java Programming | Dremendo
Let’s see the different ways of initializing a 2D array. int a[][]= new int[][] {{1,2,3}, {4,5,6}, {7,8,9}}; ... To store the number in each cell of the 2D array we can use the following syntax.
🌐
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.
🌐
The Revisionist
therevisionist.org › home › software engineering › java › step by step java tutorials › 6.1 java | two-dimensional array basics | 2d array making, finding length & ragged arrays
6.1 Java | Two-Dimensional Array Basics | 2D Array Making, Finding Length & Ragged Arrays - The Revisionist
October 12, 2016 - (a) The index of each subscript of a two dimensional array is an int value, starting from 0. To assign the value 7 to a specific element at row 2 and column 1, as shown in table (b), you can use the following syntax: ... To make the a point clear: the 1st bracket [] is references the rows. The 2nd [] is references the columns. *Note that a common mistake is to use matrix[2, 1] to access the element at row 2 and column 1. In Java, each subscript must be enclosed in a pair of square brackets.
🌐
HWS Math
math.hws.edu › javanotes › c7 › s6.html
Javanotes 9, Section 7.6 -- Two-dimensional Arrays
For example, A = new int[][] { ... 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....
🌐
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 - Declaring and initializing a 2D array in Java entails stating the Array’s type and dimensions and, if desired, giving the elements in the array values. Here is an explanation of the procedure and some examples of declaration and initialization techniques: The following is the syntax for declaring ...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
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.
🌐
Tutorial Gateway
tutorialgateway.org › two-dimensional-array-in-java
Two Dimensional Array in Java
March 23, 2025 - 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.
🌐
Programiz
programiz.com › java-programming › multidimensional-array
Java Multidimensional Array (2d and 3d Array)
Before we learn about the multidimensional array, make sure you know about Java array. A multidimensional array is an array of arrays. Each element of a multidimensional array is an array itself. For example, ... Here, we have created a multidimensional array named a. It is a 2-dimensional array, that can hold a maximum of 12 elements,