Declaration
Two-dimensional arrays are objects. A variable such as gradeTable
is a reference to a 2D array object. The declaration
int[][] myArray ;
says thatmyArray
is expected to hold a reference to a 2D array ofint
. Without any further initialization, it starts out holdingnull
.Allocation
The declaration
says thatint[][] myArray = new int[3][5] ;
myArray
can hold a reference to a 2D array of int
, creates an array object of 3 rows and 5 columns, and puts the reference in myArray
. All the cells of the array are initialized to zero. The declaration int[][] myArray = {
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
};
does exactly the same thing as the previous declaration (and would not ordinarily be used.)
Initialization
The declaration
int[][] myArray = {
{8,1,2,2,9},
{1,9,4,0,3},
{0,3,0,0,7}
};
No comments:
Post a Comment