This is array initializer syntax, and it can only be used on the right-hand-side when declaring a variable of array type. Example:

int[] x = {1,2,3,4};
String[] y = {"a","b","c"};

If you're not on the RHS of a variable declaration, use an array constructor instead:

int[] x;
x = new int[]{1,2,3,4};
String[] y;
y = new String[]{"a","b","c"};

These declarations have the exact same effect: a new array is allocated and constructed with the specified contents.

In your case, it might actually be clearer (less repetitive, but a bit less concise) to specify the table programmatically:

double[][] m = new double[4][4];

for(int i=0; i<4; i++) {
    for(int j=0; j<4; j++) {
        m[i][j] = i*j;
    }
}
Answer from nneonneo on Stack Overflow
🌐
Huda Tutorials
hudatutorials.com › java › basics › java-arrays › java-double-array
Java double Array - double Array in Java
May 18, 2024 - In this tutorial you can learn how to declare Java double Array, how to assign values to Java double Array and how to get values from Java double Array.
🌐
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
How to initialize a global array in which number of columns varies? eg: int a[][] = new int[3][]; How to initialize it if I don't know the number of columns at present?ReplyDelete ... Hello @Akshay, you can do this with two dimensional array where just first index is mandatory but with one dimensional array you must specify number of items. You can see my post 6 ways to declare two dimensional array in Java for more details.Delete
🌐
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 ...
🌐
Codecademy
codecademy.com › learn › learn-java › modules › java-two-dimensional-arrays › cheatsheet
Learn Java: Two-Dimensional Arrays Cheatsheet | Codecademy
In Java, initializer lists can be used to quickly give initial values to 2D arrays. This can be done in two different ways. If the array has not been declared yet, a new array can be declared and initialized in the same step using curly brackets.
🌐
Runestone Academy
runestone.academy › ns › books › published › apcsareview › Array2dBasics › a2dDAS.html
10.3. Declaring 2D Arrays — AP CSA Java Review - Obsolete
When arrays are created their contents are automatically initialized to 0 for numeric types, null for object references, and false for type boolean. 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 ...
🌐
Know Program
knowprogram.com › java › double-array-java
Double Array in Java - Know Program
Know Program | Learn to Code for Free. Java Tutorial, Program, and Quiz, C Tutorial, Program, and Quiz. Learn Oracle database, JDBC.
🌐
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
🌐
TutorialsPoint
tutorialspoint.com › home › java/util › arrays.fill() method in java
Java Arrays fill(double[], double) Method
September 1, 2008 - Using fill(double[], double) method, we're filling the array with a give value and then updated array elements are printed again. package com.tutorialspoint; import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { // initializing double array double arr[] = new double[] { 10.0, 20.0, 15.0 }; ...
🌐
Programiz
programiz.com › java-programming › multidimensional-array
Java Multidimensional Array (2d and 3d Array)
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); } } ... In the above example, we are creating a multidimensional array named a.
🌐
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
This is the key to writing an algorithm involving multi-dimensional arrays like looping through a 2D array, searching elements, etc. 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.
🌐
Sentry
sentry.io › sentry answers › java › how to initialize an array in java?
How to initialize an array in Java? | Sentry
In Java, the array object is used to store multiple elements of the same type. These elements are stored in contiguous memory, the length of which is immutable once initialization is complete.
🌐
Programiz
programiz.com › java-programming › arrays
Java Array (With Examples)
In Java, here is how we can declare an array. ... Here, data is an array that can hold values of type double.
🌐
Baeldung
baeldung.com › home › java › java array › initializing arrays in java
Initializing Arrays in Java | Baeldung
December 16, 2024 - These values represent the array elements’ initial state before we explicitly assign any values. Arrays of int, short, long, float, and double data types set all elements to zero by default:
🌐
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   November 13, 2025
🌐
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 - Each element in the above 2d array ... value. You already know that when initializing the 2d array, you can initialize the individual elements of the array to a value....
🌐
Runestone Academy
runestone.academy › ns › books › published › csjava › Unit9-2DArray › a2dSummary.html
9.3. 2D Arrays Summary — CS Java
Initialize a 2d array of integers named nums so that it has 1,2,3 in the first row and 4,5,6 in the second row.