Grammar
0
Q:

java 2d array length

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);
  }
}
4
  int[][] test; 
  test = new int[5][10];

  int row = test.length;
  int col = test[0].length;
1
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 // gives count of rows
    System.out.println(foo[0].length); //3 // gives count of columns for particular row
    System.out.println(foo[1].length); //4
}
2
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
}
2

New to Communities?

Join the community