Here is one way to do it. It is a "3D" array. For an array of [R][C][Other]

  • the first level R is the number of rows.
  • the second is C the number of columns.
  • the third is the size of the array in each [r][c] cell.
int ASize = 20;
int[][][] loc = new int[5][5][2];
for (int size = 0, xy = ASize / 2; size < 5;
        size++, xy += ASize) {
    for (int size2 = 0, xy2 = ASize / 2; size2 < 5;
            size2++, xy2 += ASize) {
        loc[size][size2][0] = xy2;
        loc[size][size2][1] = xy;
    }
    
}
for (int[][] arr : loc) {
    System.out.println(Arrays.deepToString(arr));
}

Prints

[[10, 10], [30, 10], [50, 10], [70, 10], [90, 10]]
[[10, 30], [30, 30], [50, 30], [70, 30], [90, 30]]
[[10, 50], [30, 50], [50, 50], [70, 50], [90, 50]]
[[10, 70], [30, 70], [50, 70], [70, 70], [90, 70]]
[[10, 90], [30, 90], [50, 90], [70, 90], [90, 90]]

This prints as follows.

  • Multiple dimensions in Java are really arrays of arrays.
  • so the loop iterates over each row (which is a [5][2] array) and prints each row using Arrays.deepToString()
  • Arrays.toString() is normally used to print arrays but only the first level.
Answer from WJS on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › multidimensional-arrays-in-java
Java Multi-Dimensional Arrays - GeeksforGeeks
Example 2: Java program to assigning the values in 3D array using indexes.
Published   March 14, 2026
🌐
W3Schools
w3schools.com › java › java_arrays_multi.asp
Java Multi-Dimensional Arrays
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... A multidimensional array is an array that contains other arrays.
Top answer
1 of 2
2

Here is one way to do it. It is a "3D" array. For an array of [R][C][Other]

  • the first level R is the number of rows.
  • the second is C the number of columns.
  • the third is the size of the array in each [r][c] cell.
int ASize = 20;
int[][][] loc = new int[5][5][2];
for (int size = 0, xy = ASize / 2; size < 5;
        size++, xy += ASize) {
    for (int size2 = 0, xy2 = ASize / 2; size2 < 5;
            size2++, xy2 += ASize) {
        loc[size][size2][0] = xy2;
        loc[size][size2][1] = xy;
    }
    
}
for (int[][] arr : loc) {
    System.out.println(Arrays.deepToString(arr));
}

Prints

[[10, 10], [30, 10], [50, 10], [70, 10], [90, 10]]
[[10, 30], [30, 30], [50, 30], [70, 30], [90, 30]]
[[10, 50], [30, 50], [50, 50], [70, 50], [90, 50]]
[[10, 70], [30, 70], [50, 70], [70, 70], [90, 70]]
[[10, 90], [30, 90], [50, 90], [70, 90], [90, 90]]

This prints as follows.

  • Multiple dimensions in Java are really arrays of arrays.
  • so the loop iterates over each row (which is a [5][2] array) and prints each row using Arrays.deepToString()
  • Arrays.toString() is normally used to print arrays but only the first level.
2 of 2
1

While defining a nested array you have to use a pair of square brackets [] for each level of nesting. And for "3d" array it would be [][][].

Note that there's actually no "2d" or "3d" array in Java. We can create a nested array, i.e. an array that contains other arrays.

While creating a nested array, only the length of the outer (enclosing) array needs to be provided. And you can omit declaring the sizes of the inner arrays, that can useful when inner arrays may differ in length.

I.e. this declaration will also be valid:

int[][][] loc = new int[5][][];

Another important thing about arrays that you need to be aware that although they are objects and inherit all behavior from the Object class, array don't have their own classes. As a consequence of this, if you invoke toString(), hasCode() and equals() on an array, a default implementation from the Object class would be invoked. Therefore, an attempt to print an array will result in strange symbols appearing on the console.

For that reason, Arrays utility class if your friend when need to print or compare arrays.

public static void main(String[] args) {

    int[][][] loc = new int[5][5][2];
    
    for (int row = 0; row < loc.length; row++) {
        for (int col = 0; col < loc[row].length; col++) {
            loc[row][col][0] = (1 + 2 * row) * 10;
            loc[row][col][1] = (1 + 2 * col) * 10;
        }
    }    

    print3DArray(loc);
}

public static void print3DArray(int[][][] arr) {
    for (int row = 0; row < arr.length; row++) {
        for (int col = 0; col < arr[row].length; col++) {
            System.out.print(Arrays.toString(arr[row][col]) + " ");
        }
        System.out.println();
    }
}

Output:

[10, 10] [10, 30] [10, 50] [10, 70] [10, 90] 
[30, 10] [30, 30] [30, 50] [30, 70] [30, 90] 
[50, 10] [50, 30] [50, 50] [50, 70] [50, 90] 
[70, 10] [70, 30] [70, 50] [70, 70] [70, 90] 
[90, 10] [90, 30] [90, 50] [90, 70] [90, 90]
🌐
Programiz
programiz.com › java-programming › multidimensional-array
Java Multidimensional Array (2d and 3d Array)
Remember, Java uses zero-based indexing, that is, indexing of arrays in Java starts with 0 and not 1. Let's take another example of the multidimensional array. This time we will be creating a 3-dimensional array. For example, ... Here, data is a 3d array that can hold a maximum of 24 (3*4*2) elements of type String.
🌐
Scientech Easy
scientecheasy.com › home › blog › three dimensional array in java | 3d array, example
Three Dimensional Array in Java | 3D Array, Example - Scientech Easy
February 14, 2025 - a) A multidimensional array in Java is actually an array in which each element represents another array. b) The difference between three-dimensional array and two-dimensional array is that 3D array consists of an array of 2D arrays, whereas, 2D array consists of an array of 1D arrays.
Find elsewhere
🌐
Medium
medium.com › @AlexanderObregon › understanding-multi-dimensional-arrays-in-java-7ead0c3937dd
Understanding Multi-Dimensional Arrays in Java
February 22, 2025 - While two-dimensional arrays are the most commonly used, Java allows arrays with any number of dimensions. For example, you can have a 3D array where each element in the array is a 2D array.
🌐
CodeGym
codegym.cc › java blog › random › java multidimensional array
Java Multidimensional Array
April 9, 2025 - So, multidimensional arrays in Java? They're your go-to when a plain old list won't cut it—think game boards, spreadsheets, or math grids. They're arrays of arrays, stacking data into rows and columns (2D) or even deeper, like a Rubik's cube (3D). I've been slinging Java code for over ten ...
🌐
Educative
educative.io › blog › what-is-a-3-d-array
What is a 3-D array?
August 18, 2025 - Now we understand what a 3-D array means, it is time for us to understand how we could program it, and for that purpose, we will be using C++ and Java programming languages. Click the "Run" button to execute the below example. ... Line 12: We print the value of the element at the index [0][0][0] of the array arr.
🌐
Refreshjava
refreshjava.com › java › multi-dimensional-array
Java Multidimensional Arrays (2d and 3d Array) - RefreshJava
A three dimensional array is an array of 2D arrays, which means each elements in 3D array will be a 2D array.
🌐
Nabble
imagej.273.s1.nabble.com › How-to-define-a-3D-array-td3695869.html
ImageJ - How to define a 3D array?
June 16, 2008 - ImageJ · How to define a 3D array · ‹ Previous Topic Next Topic › · Locked 5 messages · Sasmita Rath · Reply | Threaded · Open this post in threaded view · Michael Doube
🌐
Shubham's blog
shubhamv.hashnode.dev › multi-dimensional-arrays3d-arrays-in-programming
Multi-Dimensional Arrays(3D Arrays) in programming
October 14, 2022 - 3D Array in Java Java allows for arrays of two or more dimensions. a two-dimensional (2D) array is an array of arrays. A three-dimensional (3D) array is an array of arrays. In programming, an array can have two, three, or even ten or more ...
🌐
Sololearn
sololearn.com › en › Discuss › 1691924 › how-one-can-fill-a-multidimensional-array-in-java
How one can fill a multidimensional array in Java?
February 17, 2019 - Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Codemistic
codemistic.github.io › java › multidimensional-array-java.html
Multi-dimensional arrays | Java Tutorials | CodeMistic
array_name[row_index][column_index] = value; For example: arr[0][0][0] = 6; Example of Multidimensional 3D Java Array · class GFG { public static void main(String[] args) { int[][] arr = new int[10][20][23]; arr[0][0][0] = 65; System.out.println("arr[0][0][0]= " + arr[0][0][0]); } } output: arr[0][0][] = 65 ·
🌐
Coderanch
coderanch.com › t › 609235 › java › Array-Java
3D Array in Java Help (Java in General forum at Coderanch)
April 10, 2013 - Junilu Lacar wrote:You would use the same indexing scheme you used to put values into the array in the first place. That doesn't change. Note that Java does not have true multidimensional arrays. What you have declared is an array which has elements that are arrays which themselves have elements ...
🌐
EDUCBA
educba.com › home › software development › software development tutorials › java tutorial › 3d arrays in java
3D Arrays in Java | Creating, Inserting, Initializing the Elements - Example
May 14, 2024 - Guide to 3D Arrays in Java. Here we discuss how to create arrays, how to insert a value, how to access, remove, and update.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Coding Shuttle
codingshuttle.com › java-programming-handbook › java-multidimensional-arrays
Java Multidimensional Arrays | Coding Shuttle
April 9, 2025 - We can also declare higher-dimensional arrays (3D, 4D, etc.), but 2D is the most commonly used. We can initialize a 2D array in multiple ways.
🌐
CodeScracker
codescracker.com › java › program › java-program-three-dimensional-array.htm
Java Three Dimensional Array Program
import java.util.Scanner; public class CodesCracker { public static void main(String[] args) { int one, two, three, i, j, k; Scanner scan = new Scanner(System.in); System.out.println("---Enter the Size of Dimensions---\n"); System.out.print("How many elements to store in each 1D array: "); one = scan.nextInt(); System.out.print("How many 1D array to create: "); two = scan.nextInt(); System.out.print("How many 2D array to create: "); three = scan.nextInt(); int[][][] arr = new int[three][two][one]; System.out.print("\nEnter " +(one*two*three)+ " Elements for 3D Array: "); for(i=0; i<three; i++)
🌐
Post.Byes
post.bytes.com › home › forum › topic › software development
Arrays in Java| One D Arrays| 2 D Array |3 D Arrays - Post.Byes
April 11, 2021 - / public class ImplementThreeD Array { public static void main(String[] args) { / ############### ############### ######### int [][][] threeDArray =new int[2][][]; threeDArray[0] =new int[3][]; threeDArray[0][0]=new int[1]; threeDArray[0][1]=new int[2]; threeDArray[0][2]=new int[3]; threeDArray[1]=new int[2][2]; ############### ############### ############### */ Scanner scanner=new Scanner(System. in); System.out.prin tln("Plz Enter base siz 3D Array"); int basSize1=scanne r.nextInt(); System.out.prin tln("Plz Enter base size of 2D Array"); int basSize2=scanne r.nextInt(); System.out.prin tln(