An array type variable is denoted by a base type followed by the empty brackets, []. Alternatively, Java accepts a C-style declaration with the brackets placed after the array name. The following are equivalent:
int [] arrayOfInts; // preferred
int arrayOfInts []; // C-style
In each case, arrayOfInts is declared as an array of integers. The size of the array is not
yet an issue because we are declaring only the array type variable. We have not yet created
an actual instance of the array class, with its associated storage. It’s not even possible
to specify the length of an array when declaring an array type variable. The size is strictly
a function of the array object itself, not the reference to it.
An array of reference types can be created in the same way:
String [] someStrings;
Button [] someButtons;
0 comments:
Post a Comment