Order doesn't matter, and in fact the former form is more readable:

final const int RED = 0;
final const int GREEN = 1;
final const int BLUE = 2;

int[][][] colorImage = new int[numRows][numColumns][3];
//...

int x = getSomeX();
int y = getSomeY();

int redComponent = colorImage[x][y][RED];
int greenComponent = colorImage[x][y][GREEN];
int blueComponent = colorImage[x][y][BLUE];
Answer from Strelok 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 ...
Published Β  May 4, 2026
🌐
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 - In this program, x has been declared to be a 3d array, of dimension (size) 3*3*3. The 3d array x consists of three tables, each contains three rows and three columns. The outermost for loop is to select each table. The inner for loop has been used to select each row of the table selected by ...
Discussions

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
The order shouldn't matter, so one isn't more effective than the other. The only thing that matters is that whatever accesses colorImage knows which dimension is used for what. Bit more context on multidimensional arrays here. ... I'm not sure if its a good idea to put everything in an 3dimensional ... 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
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
🌐
CodeScracker
codescracker.com β€Ί java β€Ί program β€Ί java-program-three-dimensional-array.htm
Java Three Dimensional Array Program
public class CodesCracker { public static void main(String[] args) { int[][][] arr = { { {1, 2, 3, 4},{5, 6, 7, 8},{9, 10, 11, 12} }, { {13, 14, 15, 16},{17, 18, 19, 20},{21, 22, 23, 24} }}; for(int i=0; i<2; i++) { for(int j=0; j<3; j++) { for(int k=0; k<4; k++) { System.out.print("arr["+i+"]["+j+"]["+k+"] = " +arr[i][j][k]+"\t"); } System.out.print("\n"); } } } } The snapshot given below shows the sample output produced by above program on three-dimensional array in Java:
🌐
Programiz
programiz.com β€Ί java-programming β€Ί multidimensional-array
Java Multidimensional Array (2d and 3d Array)
Here, we have created a multidimensional array named a. It is a 2-dimensional array, that can hold a maximum of 12 elements, ... 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.
🌐
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.
Call Β  +917738666252
Address Β  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
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 ...
Find elsewhere
🌐
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.
🌐
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.
🌐
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.
🌐
Shubham's blog
shubhamv.hashnode.dev β€Ί multi-dimensional-arrays3d-arrays-in-programming
multi-dimensional java jagged-array development programming DSA
October 14, 2022 - Array threeD_arr is a three-dimensional array. It can hold 6000 floating-point elements (10x20x30=4500). can you see the power of declaring an array over variables? When it comes to holding multiple values in Java programming, we would need ...
🌐
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. It can be declared and initialized as follows: ... You can initialize a multidimensional array either at the time of declaration or later using nested loops. ... Game development: Representing game ...
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]
🌐
YouTube
youtube.com β€Ί watch
6.13 3D ( Multi Dimensional ) Array in Java - YouTube
Java array is an object the contains elements of similar data type. 3D array are collections of 2D arrays. In 3D array data is stored in row and column base...
Published Β  January 12, 2016
🌐
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.
🌐
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.
Top answer
1 of 4
18
static String[][][] School= new String[1000][20][5]; 

Consider figure which has 3 Dimension.

So when you insert School[0][0][0]="A1" it means you have entered element at 0,0,0 position.

From 0,0,0 this will move upto the position 1000,20,5.

You can insert like this But you have so many elements.

School[0][0][0]="A1"
School[0][0][1]="A2"
School[0][0][2]="A3"
.....
School[0][1][0]="B1"
School[0][1][1]="B2"
School[0][1][2]="B3"
......

In 3D array elements look like

int[3][4][2] array3D
// means Three (4x2) 2 Dimensional Arrays 

 int[4][2]
 //means Four 1 dimensional arrays.

Now how to add elements in 3D array?

At Start you can directly use

int[][][] threeDArray = 
    {  { {1,   2,  3}, { 4,  5,  6}, { 7,  8,  9} },
       { {10, 11, 12}, {13, 14, 15}, {16, 17, 18} },
       { {19, 20, 21}, {22, 23, 24}, {25, 26, 27} } };

This is very tedious task in your case as you want to insert details at every position. As you have 1000 records.

Your array will have elements like this

NOTE:It's not recommended to use 3D array for this purpose.

Suggestion:Declare a class with three Strings create constructor with this three parameters and put getter and setters to get and set values via Objects

2 of 4
3

I will suggest instead of using a 3D array, you shall create a Student Class that will hold all the information for a student and A Class for SchoolClass that will hold a list of students in the class and name of class and you can maintain an Array of SchoolClass to serve the purpose.

This way you will be able to manage it better.

Hope this helps

🌐
Reddit
reddit.com β€Ί r/java β€Ί what is more memory effiecient, one 3 dimensional array or 3 one dimensional arrays?
r/java on Reddit: What is more memory effiecient, one 3 dimensional Array or 3 one dimensional Arrays?
March 31, 2012 -

I could write a program using either system, however 3 one dimensional arrays would be a little simpler to code. If one 3 dimensional Array was a lot more memory efficient i would put in the extra effort to use that.

Top answer
1 of 4
8
If you wanted to replace 3 one dimensional arrays, you wouldn't need a 3 dimensional array, just a 2 dimensional array that has 3 items. Each item would be one of your original arrays. Java would still be tracking your 3 original arrays and also tracking the array containing them versus tracking 3 separate instance variables if you declared them individually. Either way you're not going to see any measurable difference between the two options so use what's going to be easier for you to code and easier to understand when you come back to it later.
2 of 4
3
I'm a little surprised that no one has mentioned this, but in Java all arrays are one-dimensional. Two-dimensional (or three or four or whatever) arrays are illusory. Writing int[][] crank = new int[3][15] is identical to: int[][] crank = new int[3][]; crank[0] = new int[15]; crank[1] = new int[15]; crank[2] = new int[15]; Neither offers any performance benefits. Even afterwards you can re-assign any component array with something like "crank[1] = new int[25]" and your second-level arrays will have 15, 25 and 15 elements. Java's multi-dimensional arrays are really nothing like C's. As sazzer pointed out, write it however you find easiest to code and maintain, or if you're a student, how you think your teacher would want you to. You could do it as one big one-dimensional array and do all the indexing manually, but I'd be very surprised if any benchmarks show that you actually outsmarted the compiler/optimizer. Also, three one dimensional arrays is equivalent to a two dimensional array. A three dimensional array is a different beast, but in Java is still just an array of arrays of arrays, not a contiguous block of memory.