Unlock Your Python Backend Career: Build 30 Projects in 30 Days. Join now for just $54

Arrays in Java

3-Dimensional (3D) Array in Java

A 3D array is an extension of a 2D array, adding another dimension. It can be used to represent students in different schools and classes.

Syntax:

dataType[][][] arrayName = new dataType[depth][rows][columns];

or

dataType[][][] arrayName = {
    {
        {value1, value2},
        {value3, value4}
    },
    {
        {value5, value6},
        {value7, value8}
    }
};

Example:

Students in multiple schools and classes.

class MasterBackend {
    public static void main(String[] args) {
        // 3D Array: Students in multiple schools and classes
        String[][][] schoolStudents = {
            {{"Ayush", "Rahul"}, {"Neha", "Priya"}},  // School 1
            {{"Ravi", "Anita"}, {"Vikas", "Sita"}}    // School 2
        };

        System.out.println("Students in multiple schools and classes:");
        for (int i = 0; i < schoolStudents.length; i++) {
            System.out.println("School " + (i + 1) + ":");
            for (int j = 0; j < schoolStudents[i].length; j++) {
                System.out.print("  Class " + (j + 1) + ": ");
                for (int k = 0; k < schoolStudents[i][j].length; k++) {
                    System.out.print(schoolStudents[i][j][k] + " ");
                }
                System.out.println();
            }
        }
    }
}

Output:

Students in multiple schools and classes:
School 1:
  Class 1: Ayush Rahul
  Class 2: Neha Priya
School 2:
  Class 1: Ravi Anita
  Class 2: Vikas Sita

Whenever you're ready

There are 4 ways we can help you become a great backend engineer:

The MB Platform

Join 1000+ backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learnings and set schedules, and solve backend engineering tasks, exercises, and challenges.

The MB Academy

The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.

Join Backend Weekly

If you like post like this, you will absolutely enjoy our exclusive weekly newsletter, Sharing exclusive backend engineering resources to help you become a great Backend Engineer.

Get Backend Jobs

Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board