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
Elements in three-dimensional arrays are commonly referred by x[i][j][k] where 'i' is the array number, 'j' is the row number and 'k' is the column number. Note: In arrays if size of array is N. Its index will be from 0 to N-1. Therefore, for row_index 2, actual row number is 2+1 = 3. Example: Accessing the elements of 3D array using indexes. ... import java.io.*; class Geeks { public static void main(String[] args){ // Creating an Array int[][][] arr = { { { 1, 2 }, { 3, 4 } }, { { 5, 6 }, { 7, 8 } } }; // Printing array at index 0 , 0 , 0 System.out.println("arr[0][0][0] = " + arr[0][0][0]); } }
Published   May 4, 2026
Discussions

Java 3D array with array as elements - Stack Overflow
Oh... Didn't know this is 3D array. Thought this is 2D array but with array elements. ... It is!! But in Java, multiple dimensional arrays are just arrays of arrays of arrays, etc. So a 2D array is a single dimensional array with single dimensional array elements. More on stackoverflow.com
🌐 stackoverflow.com
Help understanding 3D arrays in Java
you know the nested for loops used to initial a 2d array? add one more nested for loop More on reddit.com
🌐 r/learnprogramming
10
0
September 10, 2019
java - Understanding Three-Dimensional Arrays - Stack Overflow
I'm trying to wrap my head around three-dimensional arrays. I understand that they are arrays of two-dimensional arrays, but the book I'm reading said something that confuses me. In an exercise fo... More on stackoverflow.com
🌐 stackoverflow.com
How to understand three dimensional array in Java - Stack Overflow
I've tried to understand how three dimensional arrays work in Java. I know the rules two dimensional but I copmletely don't know how to use in practice three dimensional. int[] num1to3 = {1, 2, 3}... More on stackoverflow.com
🌐 stackoverflow.com
🌐
CodeScracker
codescracker.com › java › program › java-program-three-dimensional-array.htm
Java Three Dimensional Array Program
Where the innermost loop makes one dimensional array, the second innermost loop makes two dimensional array, and the outer loop makes finally the three dimensional array. Here is another program, that allows user to define the size of dimension of three dimensional array, along with its elements: 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.
🌐
Programiz
programiz.com › java-programming › multidimensional-array
Java Multidimensional Array (2d and 3d Array)
Let's see how we can use a 3d array in Java. We can initialize a 3d array similar to the 2d array. For example, // test is a 3d array int[][][] test = { { {1, -2, 3}, {2, 3, 4} }, { {-4, -5, 6, 9}, {1}, {2, 3} } }; Basically, a 3d array is an array of 2d arrays.
🌐
Educative
educative.io › blog › what-is-a-3-d-array
What is a 3-D array?
August 18, 2025 - Similarly, an array of 2-D arrays makes a 3-D ( three-dimensional) array. ... This array can store a total of 4 X 5 X 8 = 160 elements. ... Now we understand what a 3-D array means, it is time for us to understand how we could program it, and ...
🌐
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
🌐
Know Program
knowprogram.com › home › 3d array in java
3D Array in Java - [Three Dimensional Array] - Know Program
March 29, 2021 - 3D Array in Java | A three-dimensional array is a collection of 2D arrays. It is specified by using three subscripts: block size, row size, and column size. More dimensions in an array mean more data can be stored in that array.
Find elsewhere
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]
🌐
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 - The input array used is a Three-dimensional array with a varied length of columns. The enhanced for each loop used for each dimension displays the contents of the array in a tabular format. ... Answer: A Two-dimensional array is called an array of arrays and is usually organized in the form of matrices consisting of rows and columns. A Two-dimensional array finds its use mostly in relational databases or similar data structures. ... Answer: One-dimensional array in Java ...
🌐
Shubham's blog
shubhamv.hashnode.dev › multi-dimensional-arrays3d-arrays-in-programming
multi-dimensional java jagged-array development programming DSA
October 14, 2022 - ... Our array can hold 200 integer-type elements. This number is reached by multiplying the value of each dimension. In this case:10x20=200. ... Array threeD_arr is a three-dimensional array.
🌐
Artima
artima.com › insidejvm › applets › ThreeDArray.html
Three Dimensional Array Java Applet - an Interactive Illustration of the JVM
The Java virtual machine allocates these 26 arrays on the heap, initializes their components such that they form a tree, and returns the reference to the base array. To assign an int value to an element of the three-dimensional array, the Java virtual machine uses aaload to get a component of the base array.
🌐
Dr. Balvinder Taneja
drbtaneja.com › home › array with three or more dimensions in java
Array with three or more dimensions in java - Dr. Balvinder Taneja
November 27, 2024 - A three-dimensional array in Java is an array where each element is a two-dimensional array.
🌐
javaspring
javaspring.net › blog › java-threedimensional-array
Java Three-Dimensional Arrays: A Comprehensive Guide — javaspring.net
This blog post will explore the fundamental concepts, usage methods, common practices, and best practices of Java three-dimensional arrays. ... A three-dimensional array in Java is essentially an array of arrays of arrays.
🌐
Scaler
scaler.com › home › topics › java › multidimensional arrays in java
Multidimensional Arrays in Java - Scaler Topics
September 7, 2023 - In this type of initialization, java fills all the cells of the array with some base or garbage values. For int array, it fills them with zero(0). ... Number of elements in this array is 8. ... This is similar to accessing a two-dimensional array. Here, arrayIndex is the outer array index, and rowIndex and columnIndex are rows and columns of inner arrays, respectively. Printing elements of three-dimensional Arrays Three-Dimensional arrays can also be printed using for loops, for-each loops, and individually.
🌐
Daily Java Concept
dailyjavaconcept.com › home › data structure › arrays › java array guide to 3d arrays with user input
Java Array Guide to 3D Arrays with User Input - Daily Java Concept
January 13, 2024 - Just like a 2D array is an array of arrays, a 3D array is an array of 2D arrays. It introduces an additional dimension, forming a cube-like structure with elements accessible through three indices: depth, row, and column.
🌐
Refreshjava
refreshjava.com › java › multi-dimensional-array
Java Multidimensional Arrays (2d and 3d Array) - RefreshJava
Element at index 00 = 15 Element at index 01 = 20 Element at index 02 = 25 Element at index 10 = 20 Element at index 11 = 30 Element at index 12 = 40 Element at index 20 = 50 Element at index 21 = 60 Element at index 22 = 70 · A three dimensional array is an array of 2D arrays, which means ...
🌐
Medium
gondi-sai.medium.com › java-multidimensional-arrays-explained-working-with-2d-and-3d-arrays-java-no-12-0f9210ec2623
“Java Multidimensional Arrays Explained: Working with 2D and 3D Arrays”-(Java No-12) | by Gondi | Medium
September 19, 2024 - For a 3D array, think of it as an array of 2D arrays. int[][][] array3D = new int[2][3][4]; // 2 blocks, each with 3 rows and 4 columns · int value = array3D[1][2][3]; // Accesses the element in the second block, third row, and fourth column ...