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 ... Java Syllabus Java Study Plan Java Interview Q&A ... A multidimensional array is an array that contains other arrays. You can use it to store data in a table with rows and columns. To create a two-dimensional array, write each row inside its ...
🌐
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

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
In desperate need to master 2 dimensional arrays
Can you give an example of something you want to do with a 2D array that you can't figure out how to do? Or some behavior about them that confuses you? More on reddit.com
🌐 r/learnprogramming
16
5
January 30, 2024
Most common term in a two dimensional array
The way you have described it, the 2d array bit seems irrelevant to the general solution. You have a data structure that contains values and you want to find the most common value. How would you solve that in general? More on reddit.com
🌐 r/learnprogramming
64
20
August 25, 2024
[java] How to access the last element in a two dimensional array of unknown size?
A two dimensional array is just an array of arrays, so to get the last item in the last row, you can get the last array from the first dimension, and get that array's last item: int[] lastRow = array[array.length - 1]; int lastItem = lastRow[lastRow.length - 1]; Or you can get the last row's length, and access the last row & column from the 2D array: int lastRowLength = array[array.length - 1].length; int lastItem = array[array.length - 1][lastRowLength - 1]; or more concisely: int lastItem = array[array.length - 1][array[array.length-1].length - 1]; Edit: typo fixed. thanks to u/HellloWorld More on reddit.com
🌐 r/learnprogramming
5
0
May 16, 2013
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];
🌐
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 - Imagine a spreadsheet where data is arranged in rows and columns; a two dimensional array in Java mimics this structure by allowing access to elements through two indices — one for the row and one for the column.
🌐
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.
🌐
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
🌐
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 › 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.
🌐
Scaler
scaler.com › home › topics › two dimensional array in java
Two Dimensional Array In Java with Examples - Scaler Topics
June 8, 2024 - Hence, when we create a 2D array ... 2D array. 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....
🌐
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.
🌐
Hero Vired
herovired.com › learning-hub › topics › two-dimensional-array-in-java
Two-Dimensional Array in Java - Hero Vired
July 29, 2024 - The syntax declares a two-dimensional array with the name arrName that can store the object of class className in tabular form. Arrays are stored in contiguous memory locations, and numeric indexing references these memory locations.
🌐
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.
🌐
Programiz
programiz.com › java-programming › multidimensional-array
Java Multidimensional Array (2d and 3d Array)
Here, we have created a multidimensional array named a. It is a 2-dimensional array, that can hold a maximum of 12 elements, ... Remember, Java uses zero-based indexing, that is, indexing of arrays in Java starts with 0 and not 1.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › two-dimensional array in java
Two-Dimensional Array in Java | Syntax & Example Program
September 2, 2025 - How do you store tabular data like ... the two-dimensional array in Java comes in. A 2D array is essentially an array of arrays, allowing you to organize data in rows and columns....
🌐
Educative
educative.io › home › courses › data structures for coding interviews in java › two dimensional arrays
Understanding Two Dimensional Arrays in Java Programming
Initialization in Two Dimensional Arrays is done using two values for the number of Rows and Columns. Look at the following code to see how 2D array is declared and initialized in Java:
🌐
Scientech Easy
scientecheasy.com › home › blog › multidimensional array in java (2d array)
Multidimensional Array in Java (2D Array) - Scientech Easy
February 14, 2025 - Multidimensional array in Java represents 2D, 3D, . . . . arrays which is a combination of several types of arrays. For example, a two-dimensional array is a combination of two or more one-dimensional (1D) arrays.
🌐
Runestone Academy
runestone.academy › ns › books › published › apcsareview › Array2dBasics › a2dBasics.html
10.1. Introduction to 2D Arrays — AP CSA Java Review - Obsolete
Arrays in Java can store many items of the same type. You can even store items in two-dimensional (2D) arrays which are arrays that have both rows and columns. A row has horizontal elements. A column has vertical elements.
🌐
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 inside the columns.
🌐
Dremendo
dremendo.com › java-programming-tutorial › java-two-dimensional-array
Two Dimensional Array in Java Programming | Dremendo
A Two Dimensional Array in Java is a collection of 1D Array. It consists of rows and columns and looks like a table. A 2D array is also known as Matrix.