PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

Multidimensional Arrays in Java

← All stacks

Theory

51/270

Multidimensional Arrays in Java

A 2D array is an array of arrays. int[][] m = {{1, 2}, {3, 4}}; m[1][0] is row 1, column 0 → 3. Indexes start at 0.

Rows can have different lengths (jagged): new int[3][]; then m[0] = new int[2]; m[1] = new int[5];. Nested loops visit every cell: for i, for j.

Length — m.length is rows. m[i].length is columns in that row. Out of range still throws ArrayIndexOutOfBoundsException.

Let's take this on the board with one tiny Main class — no extra files. Multidimensional Arrays in Java — m[1][0] is row 1, column 0 → 3. Start from main, go line by line, and stop at each print. That output is the proof for Multidimensional Arrays.

Diagram
index →  0    1    2
  array → [10,  20,  30]
           ↑         ↑
         first   length-1
Exam tip

Say array of arrays. Show m[1][0]. Mention jagged if asked.

Example

public class Main {
  public static void main(String[] args) {
    int[][] m = {{1, 2}, {3, 4}};
    System.out.println(m[1][0]); // 3
  }
}

Multidimensional Arrays in Java — m[1][0] is row 1, column 0 → 3.

Short notes

  • Def2D array = array of arrays. m[row][col].
  • RuleIndex from 0. m.length = rows. m[i].length = that row’s columns.
  • RememberJagged = rows of different length.
  • TrapMixing row/col. Out of range exception.

Questions

1

What is a 2D array?

2

What is jagged?

Previous← Java ArraysNextJava Array length →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.