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
Discussions

Finding length of all arrays multidimensional array, Java - Stack Overflow
I would like to use a multidimensional array to store a grid of data. However, I have not found a simple way to find the length of the 2nd part of the array. For example: boolean[][] array = new b... More on stackoverflow.com
🌐 stackoverflow.com
How to get the length of any dimension of multidimensional array in Java? - Stack Overflow
7 Finding length of all arrays multidimensional array, Java More on stackoverflow.com
🌐 stackoverflow.com
Java: length of multidimensional arrays - Stack Overflow
i used goodle to find out how to find the lengths of multidimensional arrays and they've shown me these technics: a[0].length, a[1].length, a[2].length, ... More on stackoverflow.com
🌐 stackoverflow.com
Array length in a multidimensional array java - Stack Overflow
I thought once we declare the array to be a certain length we can't change it. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Coding Rooms
codingrooms.com › blog › 2d-array-length-java
https://www.codingrooms.com/blog/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.
🌐
Coderanch
coderanch.com › t › 399717 › java › multidimensional-array-length
multidimensional array length (Beginning Java forum at Coderanch)
I have the following array. data[x][y] I found some info on the net saying if I want to get the first dimension's length I do: data[x].length() However, when I compile I get: cannot resolve symbol method length() Above this part of the code I have a length method that is working fine on the same array, however I am using the following format: ... The second one that seems to work is actually calling length() on the object at the cell [x][y] which must be a String or something that has a length() method.
🌐
W3Schools
w3schools.com › java › java_arrays_multi.asp
Java Multi-Dimensional Arrays
Note: Notice how rows can have different lengths - In this example, the second row has more elements than the first, and that's perfectly valid in Java.
🌐
Stack Overflow
stackoverflow.com › questions › 24533135 › how-to-get-the-length-of-any-dimension-of-multidimensional-array-in-java
How to get the length of any dimension of multidimensional array in Java? - Stack Overflow
public static int length(Object array, int level) { if( level < 0 ) { throw new IllegalArgumentException(); } else if( level == 0 ) { if( !array.getClass().isArray() ) { throw new IndexOutOfBoundsException(); } else { return Array.getLength(array); } } else { if( !array.getClass().isArray() ) { throw new IndexOutOfBoundsException(); } else { int length = Array.getLength(array); int nextlength, maxnextlength = 0; Object element; for(int i=0; i<length; ++i) { element = Array.get(array, i); if( element != null ) { nextlength = Array.getLength(element); if( nextlength > maxnextlength ) { maxnextlength = nextlength; } } } return maxnextlength; } } }
Find elsewhere
🌐
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. I hope this helps! Let me know if you have any other questions. Tags · multidimensional-array arrays java ·
🌐
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.
🌐
ExamClouds
examclouds.com › home › java core › arrays
How to Get the Length of Arrays in Java: 1D and Multidimensional Examp
public class ArraySizeExample { public static void main(String[] args) { int[] array1 = {1, 2, 3, 4}; int[][] array2 = {{1, 1, 1}, {2, 2, 2}}; System.out.println("Length of array1 = " + array1.length); System.out.println("Length of array2 = " + array2.length); System.out.println("Length of first row in array2 = " + array2[0].length); } }
🌐
Scaler
scaler.com › home › topics › java › multidimensional arrays in java
Multidimensional Arrays in Java - Scaler Topics
September 7, 2023 - A two-dimensional array can be ... accessing, manipulating, and storing data. length 1 is the number of rows in a two-dimensional array, and length 2 is the number of columns in it....
🌐
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 ...
🌐
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 length of the 2D array in Java.
🌐
Programiz
programiz.com › java-programming › multidimensional-array
Java Multidimensional Array (2d and 3d Array)
In the above example, we are creating a multidimensional array named a. Since each component of a multidimensional array is also an array (a[0], a[1] and a[2] are also arrays). Here, we are using the length attribute to calculate the length of each row.
🌐
Processing Forum
forum.processing.org › one › topic › getting-lengths-of-multidimensional-arrays.html
Getting lengths of multidimensional arrays - Processing Forum
October 20, 2011 - This gives you the length of the nth row of a bi-dimensional array. ... thanks, but im afraid its not what i am looking for... or if it is, then forgive me, but i dont get it. let me rephrase: ... println(what to write here...); ... to get a specific dimension's length printed? eg. i'd like to see "10" printed, or "20" or "30" ... so if you have a=10; b=20; int[][] i = new int[a][b]; i.length will equal a i[0].length will equal b so will i[1].length and so forth use arraylists instead if your data requires three dimensions
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › java › multidimensional-arrays-in-java
Java Multi-Dimensional Arrays - GeeksforGeeks
Example: Taking a input from user of multidimensional array (Runtime) and print the count of even and odd number given by user. ... import java.io.*; import java.util.Scanner; class Geeks { public static void main(String[] args) { Scanner s = new Scanner(System.in); // Number of rows int n = s.nextInt(); // Initialize a 2D array int[][] arr = new int[n][]; int t = 0; // Input for each row for (int i = 0; i < n; i++) { int m = s.nextInt(); // Assuming all rows have the same column count t = m; arr[i] = new int[m]; for (int j = 0; j < m; j++) { arr[i][j] = s.nextInt(); } } int odd = 0, even = 0;
Published   May 4, 2026