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 ... in a table with rows and columns. To create a two-dimensional array, write each row inside its own curly braces:...
🌐
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

Syntax for creating a two-dimensional array in Java - Stack Overflow
In Java, a two-dimensional array can be declared as the same as a one-dimensional array. More on stackoverflow.com
🌐 stackoverflow.com
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
I am not understanding two dimensional arrays.
You’re printing the address of the array values. What you want is a string to be printed instead More on reddit.com
🌐 r/learnjava
6
2
April 2, 2018
java - Create a two dimensional string array anArray[2][2] - Stack Overflow
I'm currently on a self learning Java course and am completely stumped at one of my assignments, can anyone give me some pointers please? Bear in mind that I am completely new to Java so I need it ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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.
🌐
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, 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.
🌐
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.
Find elsewhere
🌐
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.
🌐
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.
🌐
Runestone Academy
runestone.academy › ns › books › published › csjava › Unit9-2DArray › a2dSummary.html
9.3. 2D Arrays Summary — CS Java
In this chapter you learned about two dimensional arrays. A two dimensional array stores objects in a 2d table. You can think of it as storing objects in rows and columns, but it actually uses an array of arrays to store the objects as shown below. In this chapter you learned how to declare ...
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];
🌐
Reddit
reddit.com › r/learnprogramming › need help in java specifically 2d array
r/learnprogramming on Reddit: Need help in Java specifically 2D Array
April 25, 2023 -

I'm creating a program that will sum up the outer squares(1) as well as the inner ones(2)(3).

I've already figured out how to sum up the outer boundaries. But, I can't sum up the inner boundaries.

The current dimension is 6x6 but it also needs to be flexible depending on user preference.

Can anyone help? T.T

111111
122221
123321
123321
122221
111111

🌐
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.
🌐
Carnegie Mellon University
cs.cmu.edu › ~mrmiller › 15-110 › Handouts › arrays2D.pdf pdf
Two-Dimensional Arrays 15-110 Summer 2010 Margaret Reid-Miller
Two-Dimensional Arrays · • Two-dimensional (2D) arrays are indexed by two · subscripts, one for the row and one for the column. • Example: row col · rating[0][2] = 2! !rating[1][3] = 8! 0 · 1 · 2 · 3 · 0 · 4 · 6 · 2 · 5 · 1 · 7 · 9 · 4 · 8 · 2 ·
🌐
Reddit
reddit.com › r/learnjava › i am not understanding two dimensional arrays.
r/learnjava on Reddit: I am not understanding two dimensional arrays.
April 2, 2018 -

Hey guys! I made a project last week using one dimensional arrays, and it went easy and I felt proud. Now, I got to two dimensional arrays and it all went south, fast. I will post last weeks code to help anyone understand this ones purpose.

Purpose of this weeks project is to make a lottery of three numbers, if a players numbers match the three drawn numbers, they win. Simple as that. My outputs are horrific looking though, and I am sure I can do this more simply than I am. My outputs look like "Player Number [I@3b6eb2ec:[I@3b6eb2ecPlayer Number [I@3b6eb2ec:[I@1e643fafPlayer Number [I@3b6eb2ec:[I@6e8dacdfPlayer Number [I@3b6eb2ec:[I@7a79be86". I haven't made the if statement to match the drawn numbers to the players numbers yet.

Powerball (Old Good Code): https://pastebin.com/xeGR5pQM

Lottery (Unfinished): https://pastebin.com/hQUhvTRk

🌐
Baeldung
baeldung.com › home › java › java array › print a java 2d array
Print a Java 2D Array | Baeldung
August 23, 2024 - Java, a versatile programming language, offers multiple methods for handling and manipulating arrays. Specifically, 2D arrays provide a convenient way to organize and store data in a grid-like structure.
🌐
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.
🌐
Medium
medium.com › buzz-code › java-8-two-dimensional-array-35542b4ced9
Java 8 | Two Dimensional Array
January 12, 2021 - Hi y’all! Welcome to another Java session with me, and today I’m going to talk about the Two Dimensional Array. This is not that different with the one dimensional array, only difference between them, is that the two dimensional array is just a array of the one dimensional array!
🌐
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....
🌐
Educative
educative.io › home › courses › data structures for coding interviews in java › two dimensional arrays
Understanding Two Dimensional Arrays in Java Programming
Learn how to declare, initialize, and use two dimensional arrays in Java, including managing rows, columns, and common pitfalls.