Tuesday, October 26, 2010

Length of a 2D Array

The length of a 2D array is the number of rows it has. You might guess that "length" could be defined as a number pair (rows, columns). But the number of columns may vary from row to row so this will not work.

        int arr[][] = new int[2][4];

so arr.length = 2, and arr[0].length=4 i.e. length of row.

(Note we are using length and not length() )

No comments:

Post a Comment