how to find length of a 2d array in java code example
Example 1: how to get the dimensions of a 2d array in java
public class Main {
public static void main(String[] args) {
int[][] test = new int[10][4];
int rows = test.length;
int coloumns = test[0].length;
System.out.println(rows);
System.out.println(coloumns);
}
}
Example 2: java 2d array length
int[][] test;
test = new int[5][10];
int row = test.length;
int col = test[0].length;
Example 3: 2d array length in java
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);
System.out.println(foo[0].length);
System.out.println(foo[1].length);
}
Example 4: java length of matrix
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);
System.out.println(foo[0].length);
System.out.println(foo[1].length);
}