
An initialization list can be
given only when the array
is declared.Attempting to
assign values to an array
using an initialization list
after the array is instanti-
ated will generate a com-
piler error.
COMMON ERROR
TRAP
The new keyword is not
used when an array is
instantiated using an ini-
tialization list.No size is
given;the number of val-
ues in the list specifies the
size of the array.
COMMON ERROR
TRAP
468 CHAPTER 8 Single-Dimensional Arrays
Similarly, this statement:
String [ ] cdTracks = new String [15];
is equivalent to:
String [ ] cdTracks;
cdTracks = new String [15];
8.1.4 Assigning Initial Values to Arrays
Java allows you to instantiate an array by ...