will create the array intArray with two elements and initialize it with zero values, the default
value for numbers. The reason for the new keyword is that an array is actually an object in Java.
Objects in Java are created using the new keyword, as we shall see in Chapter 4.
Array elements are counted from zero, so
intArray[0] = 1;
assigns the value of 1 to the first element of
intArray.
Note that once an array is created, its
size cannot be changed.
An example of all this is the 0utputArray program, which assigns the values of 1 and 2
to an integer array and outputs the results.
OutputArray
1 public
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.