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
To access an element of a two-dimensional array, you need two indexes: the first for the row, and the second for the column. Remember: Array indexes start at 0. That means row 0 is the first row, and column 0 is the first column.
🌐
GeeksforGeeks
geeksforgeeks.org › java › multidimensional-arrays-in-java
Java Multi-Dimensional Arrays - GeeksforGeeks
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
People also ask

What is the syntax of two-dimensional arrays in Java?
The basic syntax of a 2D array in Java is datatype[][] arrayName = new datatype[rows][columns];. This applies to both primitive and object-based arrays. The basic syntax of a 2D array in Java is datatype[][] arrayName = new datatype[rows][columns]; . This applies to both primitive and object-based arrays.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › two-dimensional array in java
Two-Dimensional Array in Java | Syntax & Example Program
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
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
w3schoolsua.github.io › java › java_arrays_multi_en.html
Java Multi-Dimensional Arrays. Lessons for beginners. W3Schools in English
Java Multi-Dimensional Arrays. Syntax. Access Elements. Change Element Values. Loop Through a Multi-Dimensional Array. We can also use a for loop inside another for loop to get the elements of a two-dimensional array (we still have to point to the two indexes).
🌐
Dremendo
dremendo.com › java-programming-tutorial › java-two-dimensional-array
Two Dimensional Array in Java Programming | Dremendo
... System.out.println(a[0][0]+" "+a[0][1]+" "+a[0][2]); System.out.println(a[1][0]+" "+a[1][1]+" "+a[1][2]); System.out.println(a[2][0]+" "+a[2][1]+" "+a[2][2]); ... We can also store as well as access the numbers in a 2D array using either ...
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › two-dimensional array in java
Two-Dimensional Array in Java | Syntax & Example Program
September 2, 2025 - Learn how to use two-dimensional array in Java with syntax, examples, and step-by-step explanations. Covers primitive and object arrays in detail.
🌐
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. ... Let's look at a code example. int[][] oddNumbers = { {1, 3, 5, 7}, ...
Find elsewhere
🌐
Software Testing Help
softwaretestinghelp.com › home › java › multidimensional arrays in java (2d and 3d arrays in java)
MultiDimensional Arrays In Java (2d and 3d Arrays In Java)
April 1, 2025 - This Tutorial on Multidimensional Arrays in Java Discusses how to Initialize, Access and Print 2d and 3d Arrays in Java with Syntax & Code Examples.
🌐
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.
🌐
Codecademy
codecademy.com › learn › learn-java › modules › java-two-dimensional-arrays › cheatsheet
Learn Java: Two-Dimensional Arrays Cheatsheet | Codecademy
... 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 is used for the desired column.
🌐
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 using nested for loops, in which the first loop is used to iterate over the rows and the second is used to iterate over the columns.
🌐
W3Schools
w3schools.in › java › arrays
Java Arrays - W3Schools
The syntax used for instantiating arrays within a Java program is: Example: char[] refVar; int[] refVar; short[] refVar; long[] refVar; int[][] refVar; //two-dimensional array · By using new operator array can be initialized. Example: int[] age = new int[5]; //5 is the size of array.
🌐
CodeGym
codegym.cc › courses › new java syntax › two-dimensional arrays
Lecture: Two-dimensional arrays - New Java Syntax - CodeGym
When we create an array using new int [2][5];, do we have a table of 'two rows and 5 columns' or is it 'two columns and 5 rows'?" "In other words, it is not entirely clear whether we are first specifying the width and then the 'height... or vice versa, first the height and then width?"
🌐
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.
🌐
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....
🌐
Scientech Easy
scientecheasy.com › home › blog › multidimensional array in java (2d array)
Multidimensional Array in Java (2D Array) - Scientech Easy
February 14, 2025 - Learn multidimensional array in java with example program, two dimensional array in java with example, how to declare and initialize 2D array
🌐
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 ...
🌐
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 - When you initialize a 2D array, you must always specify the first dimension(no. of rows), but providing the second dimension(no. of columns) may be omitted. Java compiler is smart enough to manipulate the size by checking the number of elements ...
🌐
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 - 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.