Simple Java array syntax which i'm confused over

public static void main(String[] args) {


    int[][] b = {{0, 0, 0, 1},
                 {0, 0, 1, 1},
                 {0, 1, 1, 1}};

    int[] u = new int[b.length];
    for (int i = 0; i < u.length; i++) {
        for (int j = 0; j < b[i].length; j++) {
            u[i] = u[i] +b[i][j];

        }
        System.out.println(u[i]);
      }
   }

What is the differences between written b[i].length; and b.length;

When i run this code with b[i].length; the output is 1,2,3.

When running with b.length; gives the output 0,1,2

Jon Skeet
people
quotationmark

b refers to an array of arrays.

b.length returns how many elements b has - in other words, how many "nested" arrays you have.

b[i].length returns how many elements b[i] has - in other words, the length of the nested array referred to by b[i].

people

See more on this question at Stackoverflow