two dimensional arrays

two dimensional arrays

A two dimensional array normally represents something along the lines of a box or a chart, or something else in a grid format.

THis kind of array has two [ ] after its name when you are trying to call its index, the first [ ] should have the rows index the second [ ] should have the column index. THe rows are horizontal and  the columns are vertical, the number of columns per row can also differ. Both of the indexes start at zero.

You declare a two dimensional array in two ways:

  • datatype[ ][ ]  arrayName = new datatype[numRows][numCols];
  •  datatype[ ][ ]  arrayName =

{   

{somevalueA, somevalueB, . . . } ,

{somevalueC, somevalueD , . . . }

} ;

You can get the number of rows by doing arrayName.length.

And you can get the number of columns by doing m[rowNumber].length.

One thought on “two dimensional arrays

Comments are closed.