array length, because again it is determined from the initializer list.
String[] dangers = new String[]{"Lions", "Tigers", "Bears"};
This form of array creation expression allows you to create and initialize an array anywhere. For example, you
can create and initialize an array when you invoke a method:
printStrings(new String[] { "one", "two", "many" });
An unnamed array created with new in this way is called an anonymous array.
The last value in the initializer list is also allowed to have a comma after it. This is a convenience for multiline
initializers so you can reorder, add, or remove values, without having to remember to add a comma to the old
last line, or remove it from the new last line.
Arrays of arrays can be initialized by nesting array initializers. Here is a declaration that initializes an array to
the top few rows of Pascal's triangle, with each row represented by its own array:
int[][] pascalsTriangle = {
{ 1 },
{ 1, 1 },
{ 1, 2, 1 },
{ 1, 3, 3, 1 },
{ 1, 4, 6, 4, 1 },
};
Indices in an array of arrays work from the outermost inward. For example, in the above array,
pascalsTriangle[0] refers to the int array that has one element, pascalsTriangle[1] refers to
the int array that has two elements, and so forth.
For convenience, the System class provides an arraycopy method that allows you to assign the values
from one array into another, instead of looping through each of the array elementsthis is described in more
detail in "Utility Methods" on page 665.
7.4.4. Arrays and Types
Arrays are implicit extensions of Object. Given a class X, classes Y and Z that extend X, and arrays of each,
the class hierarchy looks something like this: