Consider

public static void main(String[] args) {

    int[][] foo = new int[][] {
        new int[] { 1, 2, 3 },
        new int[] { 1, 2, 3, 4},
    };

    System.out.println(foo.length); //2
    System.out.println(foo[0].length); //3
    System.out.println(foo[1].length); //4
}

Column lengths differ per row. If you're backing some data by a fixed size 2D array, then provide getters to the fixed values in a wrapper class.

Answer from NG. on Stack Overflow
🌐
Coding Rooms
codingrooms.com › blog › 2d-array-length-java
2D Array Length Java
We use arrayname.length to determine the number of rows in a 2D array because the length of a 2D array is equal to the number of rows it has.
Discussions

Java is it possible to change 2D array length?
You've run into one of the first major problems that lead to further investigation into data structures. In most languages, arrays are declared as a fixed size and they can't be changed. The best way to increase the size of an array is to allocate a new array and copy all the values over. It's possible that you might want a different data structure to solve this problem, however. More on reddit.com
🌐 r/learnprogramming
3
2
May 20, 2020
Array length question
A two-dimensional array is just an array of arrays. So an expression like grid[0] will get the first 1-D array from the 2-D array, which will be: {'A','B','C','E'}. That array has 4 elements, so its length will be 4. More on reddit.com
🌐 r/learnjava
5
5
February 22, 2019
Two-Dimensional Arrays: Why is the length of a two-dimensional array the number of rows of the array?
As is hinted at by that snippet, a two-dimensional array is just an array of arrays. .length behaves the same with both — it returns the number of values in the array. In the case of a two-dimensional array, it’s values are one-dimensional arrays. More on reddit.com
🌐 r/javahelp
6
11
June 29, 2018
Getting lengths of multidimensional arrays - Processing Forum
Your question wasn't specific. It depends also if you are talking about arrays of primitives or of objects. I was thinking of the latter, where each "row" can have a different length and must be initialized separately.. More on forum.processing.org
🌐 forum.processing.org
October 20, 2011
🌐
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. You can use it to store data in a table with rows and columns. To create a two-dimensional array, write each row inside its own curly braces: ... To access an element of a two-dimensional array, you need two indexes: the first for the row, and the second for the column.
🌐
HappyCoders.eu
happycoders.eu › java › array-length-in-java
Array Length in Java
June 12, 2025 - The height is the length of the array (i.e., the number of rows the matrix contains), and the width is the length of the first row. Please note, however, that with a two-dimensional array in Java, all sub-arrays do not necessarily have to be ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › multidimensional-arrays-in-java
Java Multi-Dimensional Arrays - GeeksforGeeks
... A 2-D array can be seen as a table with 'x' rows and 'y' columns where the row number ranges from 0 to (x-1) and column number ranges from 0 to (y-1). A 2-D array 'x' with 3 rows and 3 columns is shown below: ... Example 1: We can add the ...
Published   May 4, 2026
🌐
Runestone Academy
runestone.academy › ns › books › published › csawesome › Unit8-2DArray › a2dSummary.html
8.3. 2D Arrays Summary — CSAwesome v1
For an array arr use arr.length to get the number of rows in the array. 2d Array Number of Columns - The number of columns (or width) is the length of the inner array.
Find elsewhere
🌐
Codecademy
codecademy.com › learn › learn-java › modules › java-two-dimensional-arrays › cheatsheet
Learn Java: Two-Dimensional Arrays Cheatsheet | Codecademy
2D arrays are declared by defining a data type followed by two sets of square brackets. ... In Java, when accessing the element from a 2D array using arr[first][second], the first index can be thought of as the desired row, and the second index is used for the desired column.
🌐
Medium
medium.com › @AlexanderObregon › understanding-multi-dimensional-arrays-in-java-7ead0c3937dd
Understanding Multi-Dimensional Arrays in Java
February 22, 2025 - The matrix.length gives you the number of rows, and matrix[i].length gives you the number of columns in the current row. This pattern of nested loops is common when working with multi-dimensional arrays. It’s important to note that in Java, each row in a 2D array can have a different number ...
🌐
CodeGym
codegym.cc › java blog › java arrays › 2d arrays in java
Java Matrix - 2D Arrays
April 8, 2025 - Or you can say for each row there will be 4 columns. The total size / number of cells in a matrix will be rows*columns = mxn = 4x4 = 16. Fig 2: The matrix[4][4] in Fig 1 represented as 2D Array in Java
🌐
Quora
quora.com › What-is-the-formula-to-calculate-the-size-of-a-2D-array
What is the formula to calculate the size of a 2D array? - Quora
Answer (1 of 2): Calculating the size of a 2D array is relatively uncomplicated in Java (and like programming languages): int numberOfColumns = arr[0].length; int numberOfRows = arr.length; Check out the explanation over here: https://www.codingrooms.com/blog/2d-array-length-java/
🌐
Medium
theonlylight.medium.com › java-101-the-difference-between-array-0-length-and-array-length-36231e4e846c
Java 101: The Difference Between array[0].length and array.length | by Light | Medium
December 12, 2023 - Therefore, array.length returns the number of 1D arrays in the 2D array, which is also the number of rows in the 2D array.
🌐
Reddit
reddit.com › r/learnjava › array length question
r/learnjava on Reddit: Array length question
February 22, 2019 -

I've been playing around with arrays lately, and i found a piece of code that i haven't figured, spoiler alert this might be a dumb/basic question but when run this code:

public static void main(String[] args) {

 char grid[][]={{'A','B','C','E'},
			   {'S','F','C','S'},
	           {'A','D','E','E'}};

System.out.println(grid[0].length); //prints 4, WHY?

}

My question is why is grid[0].length = 4?

Is it excluding the 0 position out of the array and considering 1 though 4?

I don't know what's going on to make it print that value.

🌐
W3Docs
w3docs.com › java
Getting the array length of a 2D array in Java
Note that the length field returns the length of the array along its first dimension. To get the length of the array along its second dimension, you can access the length field of one of the inner arrays.
🌐
Sololearn
sololearn.com › en › Discuss › 1043050 › what-will-happen-if-you-use-length-function-on-2d-array-
What will happen if you use length function on 2-D Array.. ??? | Sololearn: Learn to code for FREE!
January 31, 2018 - Talking about Java, the length function always gives the number of elements in the array. So is the case with 2D arrays, as the array contains 2 elements (the two arrays are treated as 2 different elements), the number returned is 2. Take this ...
🌐
Quora
quora.com › How-do-I-find-the-length-of-two-dimensional-arrays
How to find the length of two dimensional arrays - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
automateNow
automatenow.io › home › java 2d array length: 2d array examples
Java 2D array length: 2D array examples | automateNow
May 3, 2024 - To get the length of a 2D array in Java, you can use the length property of the array.
🌐
Reddit
reddit.com › r/javahelp › two-dimensional arrays: why is the length of a two-dimensional array the number of rows of the array?
r/javahelp on Reddit: Two-Dimensional Arrays: Why is the length of a two-dimensional array the number of rows of the array?
June 29, 2018 -

ETA: Here is an excerpt from the book I'm using to review Java:

...Suppose that x = new int[3][4], x[0], x[1], and x[2] are one-dimensional arrays and each contains four elements...x.length is 3 and x[0].length, x[1].length, and x[2].length are 4.

--

Given that the length of a one-dimensional array is the number of elements, doesn't it make more intuitive sense to apply the same concept to two-dimensional arrays?

🌐
JavaBeat
javabeat.net › get-length-2d-array-java
How to Get the Length of a 2d Array in Java?
January 30, 2024 - Determining the total length of the 2D array can be challenging as the number of columns per row can vary. To find the 2D array length, use “arrayname[i].length” which will return the length of each column per row as shown in this guide. This article is a practical guide for finding the ...