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
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.
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 2D array represents data in rows and columns. It can be understood as an array of 1D arrays. ... A 2-D array can be seen as a table with 'x' rows and 'y' columns where the row number ranges from 0 to (x-1) and column number ranges from 0 to (y-1). A 2-D array 'x' with 3 rows and 3 columns is shown below: ... Example 1: We can add the values directly to the array while declaring the array. ... import java.io.*; class Main { public static void main(String[] args){ // Array Intialised and Assigned int[][] arr = { { 1, 2 }, { 3, 4 } }; // Printing the Array for (int i = 0; i < 2; i++){ for (int j = 0; j < 2; j++) System.out.print(arr[i][j]+" "); System.out.println(); } } }
Published   May 4, 2026
🌐
W3Schools
w3schools.com › java › java_arrays_multi.asp
Java Multi-Dimensional Arrays
Arrays Loop Through an Array Real-Life Examples Multidimensional Arrays Code Challenge · Java Methods Java Method Challenge Java Method Parameters
🌐
Codecademy
codecademy.com › learn › learn-java › modules › java-two-dimensional-arrays › cheatsheet
Learn Java: Two-Dimensional Arrays Cheatsheet | Codecademy
2D arrays are declared by defining a data type followed by two sets of square brackets. ... 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 ...
🌐
Baeldung
baeldung.com › home › java › java array › initializing arrays in java
Initializing Arrays in Java | Baeldung
December 16, 2024 - Let’s see how to declare and initialize a three-dimensional array: ... In the code above, we have three square brackets to indicate this is a three-dimensional array. The first square bracket [3] represents the depth of the array. It indicates the number of two-dimensional arrays that the three-dimensional array contains. In this case, we have three two-dimensional arrays in the three-dimensional array. ... Here, the first index [0] indicates the first 2D array within the 3D array, the second index [0] represents the first row of the first 2D array, and the third index [1] represents the second column in the first column of the first 2D array.
🌐
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 - ... import java.io.*; class GFG ... 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; } } // printing the first three rows ...
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 - javaCopyEditint[][] numbers; // Declaring a 2D array of integers String[][] names; // Declaring a 2D array of Strings double[][] grades; // Declaring a 2D array of doubles · There are several ways to initialize a 2D array in Java.
🌐
Programiz
programiz.com › java-programming › multidimensional-array
Java Multidimensional Array (2d and 3d Array)
Here is how we can initialize a 2-dimensional array in Java. ... As we can see, each element of the multidimensional array is an array itself. And also, unlike C/C++, each row of the multidimensional array in Java can be of different lengths. ... 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); System.out.println("Length of row 3: " + a[2].length); } }
🌐
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.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map
Map - JavaScript | MDN
const kvArray = [ ["key1", "value1"], ["key2", "value2"], ]; // Use the regular Map constructor to transform a 2D key-value Array into a map const myMap = new Map(kvArray); console.log(myMap.get("key1")); // "value1" // Use Array.from() to transform a map into a 2D key-value Array ...
🌐
NeetCode
neetcode.io › solutions › 217. contains duplicate
LeetCode 217 Contains Duplicate Solution & Explanation | NeetCode
As we iterate through the array, we check whether the current value is already present in the set. If it is, that means we've seen this value before, so a duplicate exists. Using a hash set allows constant-time lookups, making this approach much more efficient than comparing every pair. Initialize an empty hash set to store seen values.
🌐
Quora
quora.com › How-do-you-initialize-a-2D-array-to-0
How to initialize a 2D array to 0 - Quora
Answer (1 of 5): The syntax for setting all elements of a 2D array to 0 vary depending upon the programming language used. The Ada language provides a simple syntax for this problem: [code]type Array_2D is array (1..4, 1..10) of Integer; A : Array_2D := (Others => (Others => 0)); [/code]Line 1 ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
Array elements are object properties in the same way that toString is a property (to be specific, however, toString() is a method). Nevertheless, trying to access an element of an array as follows throws a syntax error because the property name is not valid: ... JavaScript syntax requires properties beginning with a digit to be accessed using bracket notation instead of dot notation.
🌐
LabEx
labex.io › tutorials › initialize-2d-array-28390
Mastering 2D Array Initialization in JavaScript | LabEx
const initialize2DArray = (width, height, value = null) => { return Array.from({ length: height }).map(() => Array.from({ length: width }).fill(value) ); }; This code uses Array.from() and Array.prototype.map() to create an array of height rows, ...
🌐
Scribd
fr.scribd.com › document › 622863488 › Exercise-2D-Arrays
Java 2D Array Initialization Guide | PDF
Get the world's best ebooks, audiobooks, podcasts, magazines, documents, and more. Find anywhere else. Home to the world's documents, 300M+ and counting.
🌐
Java2Blog
java2blog.com › home › core java › java array › initialize 2d array in java
Initialize 2D array in Java - Java2Blog
January 11, 2021 - 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.
🌐
Runestone Academy
runestone.academy › ns › books › published › csjava › Unit9-2DArray › topic-9-1-2D-arrays-Day2.html
9.1.5. Set Value(s) in a 2D Array — CS Java
When arrays are created their contents are automatically initialized to 0 for numeric types, null for object references, and false for type boolean.
🌐
GeeksforGeeks
geeksforgeeks.org › java › array-declarations-java-single-multidimensional
Array Declarations in Java (Single and Multidimensional) - GeeksforGeeks
April 28, 2025 - Java · class Geeks { public static void main(String args[]) { // Creating a 2D array int[][] a; // Declare a 1D array int[] b; // Initialize arrays using the new operator a = new int[3][3]; b = new int[3]; // print 1D array for (int i = 0; ...
🌐
Openai
developers.openai.com › api › docs › guides › embeddings
Vector embeddings | OpenAI API
1 2 3 4 import pandas as pd df = pd.read_csv('output/embedded_1k_reviews.csv') df['ada_embedding'] = df.ada_embedding.apply(eval).apply(np.array)