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
🌐
Runestone Academy
runestone.academy › ns › books › published › apcsareview › Array2dBasics › a2dDAS.html
10.3. Declaring 2D Arrays — AP CSA Java Review - Obsolete
The code below creates a 2D array ... To explicitly put a value in an array you give the name of the array followed by the row index in brackets followed by the column index in brackets and then an = followed by a value....
🌐
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 - If you want to declare a 2D array ... int[3][4]; // 3 rows, 4 columns · At this point, all elements in the array are initialized to the default value for int which is 0....
Discussions

Syntax for creating a two-dimensional array in Java - Stack Overflow
If you declare the array as Object[][] ... of the 2D array. 2014-03-05T00:28:55.883Z+00:00 ... Unless you handle the null case safely for any non primitives. Whether or not you should initialize each element is completely dependent on your design. Also, just to clarify - primitives cannot be null and get instantiated to a defined default value if not assigned ... More on stackoverflow.com
🌐 stackoverflow.com
Initialization of 2D Array in Java? - Stack Overflow
Moreover, in Java, we can initialize a 2D array that is not rectangular: ... If you want to declare an array of specific size, but don’t want to specify all it’s values at once, the only solution is to use new: ... Sign up to request clarification or add additional context in comments. ... Find the answer to your question by asking. Ask question ... See similar questions with ... More on stackoverflow.com
🌐 stackoverflow.com
java - Explicitly assigning values to a 2D Array? - Stack Overflow
I've never done this before and can't find the answer. This may not be the correct data type to use for this, but I just want to assign an int, then another int without a for loop into a 2D array, ... More on stackoverflow.com
🌐 stackoverflow.com
2d array initialization in java - Stack Overflow
I want to initialize 2d array in java.How can alter this to make it right? thank u. ... Change int plate[7][7] to int[][] plate or int plate[][]. Both are correct. ... Sign up to request clarification or add additional context in comments. ... Yes, but this is not neccessary, just prettier. 2014-09-03T13:42:33.85Z+00:00 ... Find the answer to your question by asking. Ask question ... See similar questions with ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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
This way you can initialize 2D array with different length sub array as shown below : String[][] squares = new String[3][]; squares[0] = new String[10]; squares[1] = new String[20]; squares[2] = new String[30]; You can see that our 2 dimensional ...
🌐
Codecademy
codecademy.com › learn › learn-java › modules › java-two-dimensional-arrays › cheatsheet
Learn Java: Two-Dimensional Arrays Cheatsheet | Codecademy
//Given a 2d array called `arr` which stores `int` values ... In Java, initializer lists can be used to quickly give initial values to 2D arrays.
🌐
Delft Stack
delftstack.com › home › howto › java › initialize 2d array java
How to Initialize 2D Array in Java | Delft Stack
February 2, 2024 - The expression above describes that we have a 2-dimensional array with 3 rows and 3 columns. In this way, we have declared and initialized a 2-dimensional array in a single line of code. The 2-dimensional array is then printed using a nested for loop, as shown below. public class Array { public static void main(String[] args) { int[][] arr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) System.out.print(arr[row][col] + " "); System.out.println(); } } }
🌐
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 - In a 2D array, every element is associated with a row number and column number. Accessing any element of the 2D array is similar to accessing the record of an Excel File using both row number and column number. 2D arrays are useful while implementing a Tic-Tac-Toe game, Chess, or even storing the image pixels. ... import java.io.*; class GFG { public static void main(String[] args){ int n = 80, m = 5; int[][] arr = new int[n][m]; // initializing the array elements using for loop for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { arr[i][j] = i + j; } } ...
🌐
Baeldung
baeldung.com › home › java › java array › initializing arrays in java
Initializing Arrays in Java | Baeldung
December 16, 2024 - First, we indicate the second 2D array via its index [1]. Then, we add an element to the first column of the first row of that 2D array. Simply put, a three-dimensional array is an array of two-dimensional arrays.
Find elsewhere
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];
🌐
GeeksforGeeks
geeksforgeeks.org › java › multidimensional-arrays-in-java
Java Multi-Dimensional Arrays - GeeksforGeeks
... A 2-D array can be seen as ... 3 rows and 3 columns is shown below: ... Example 1: We can add the values directly to the array while declaring the array....
Published   May 4, 2026
🌐
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 - In default initialization, all ... types). ... You can initialize a 2D array with specific values using nested loops, providing explicit values for each element....
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Programiz
programiz.com › java-programming › multidimensional-array
Java Multidimensional Array (2d and 3d Array)
... class MultidimensionalArray { public static void main(String[] args) { // create a 2d array int[][] a = { {1, 2, 3}, {4, 5, 6, 9}, {7}, }; // calculate the length of each row System.out.println("Length of row 1: " + a[0].length); System.out.println("Length of row 2: " + a[1].length); ...
🌐
Runestone Academy
runestone.academy › ns › books › published › csjava › Unit9-2DArray › a2dSummary.html
9.3. 2D Arrays Summary — CS Java
2d Array Initialization - You can also initialize (set) the values in the array when you first create it. In this case you don’t need to specify the size of the array, it will be determined from the number of values that you specify. Example: String[][] seatingInfo = { {"Jamal", "Maria"}, ...
🌐
Java2Blog
java2blog.com › home › core java › java array › initialize 2d array in java
Initialize 2D array in Java - Java2Blog
January 11, 2021 - Although array is used to collect similar type of data but we can store different type of values as well. See the example below. ... If we want to initialize a variable lenght columns array at the same time of creating an array then use initialilzer block as we did in the given example. ... Java provides a class Array in reflection package that can be used to create an array.
🌐
HappyCoders.eu
happycoders.eu › java › initialize-array-java
How to Initialize Arrays in Java
June 12, 2025 - This style was adopted from the C programming language. However, all Java style guides prefer the style shown first, i.e., with the brackets after the type and before the name. We can also initialize an array with values when declaring it.
🌐
Tutorial Gateway
tutorialgateway.org › two-dimensional-array-in-java
Two Dimensional Array in Java
March 23, 2025 - In this two dimensional array program, First, We declared 2 two Dimensional Arrays a, b of size [2],[3], and initialized them with some random values.
🌐
iO Flood
ioflood.com › blog › 2d-array-java
2D Array in Java: Configuring Two-Dimensional Arrays
February 27, 2024 - The values of the array are initialized to the numbers 1 to 9. In this section, we’ve explored the fundamentals of arrays in Java, including what they are, why they are used, and how they work.
🌐
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, that you know what is a 2D or two-dimensional array in Java, let's see a couple of examples of how to create and initialize a 2D array. I have chosen both int and String arrays as they are the most common type of array you will find while coding. Our first example is about declaring a 2D array with both dimensions.