two dimensional arrays Flashcards
multidimensional array
arrays of arrays
how java stores 2-dim arrays
array of array references
create a rectangular 2-dim array (primitive)
char[][]a=new char[5][8];
break down:
> char is the type (an array of arrays of characters)
> a is the name
> 5 is the length of the array of array references
> 8 is the length of the arrays the original array is pointing to
what does the heap look like
an array of array references that point to individual arrays
char[][]a=new char[5][8];
a.length = ?
a.length = 5 a[1].length = 8
iterate row by row
for(introw = 0; row < a.length; row++) { for(intcol = 0; col < a[row].length; col++) { a[row][col] = ‘ ’;
ragged array
a 2-dim array with arrays of different sizes
crate a ragged 2-dim array
char[][]a=new char[3][];
a[0]=new char[8];
a[1]=new char[0];
a[2]=null;
1-dim initializer
int[ ] quizScoresOne= { 90, 82, 75, 66 };
create a ragged 2-dim array (primitive)
char[][]a=new char[3][];
a[0]=new char[8];
a[1]=new char[0];
a[2]=null;
2-dim initializer
int[ ][ ] quizScoresTwo= { { 90, 82, 75, 66 }, { 85 }, { 45, 77, 99 } };
create a 2-dim array (objects, nonprimative)
ObjectType [][] var=new ObjectType[MAXROW][MAXCOL];