Once an array variable has been declared, memory can be allocated to it. This is done with the new operator, which allocates memory for objects. (Remember arrays are implicit objects.) The new operator is followed by the type, and finally, the number of elements to allocate. The number of elements to allocate is placed within the [] operator. Some examples:
Java Example
counts = new int[5];
names = new String[100];
matrix = new int[5][];
The above creates initializes three arrays (the three we created in the previous example). The first array, counts, can contain 5 integer values. The second array, names, can contain 100 different string values. The last array, matrix, is actually an array of 5 integer arrays.
An alternate shortcut syntax is available for declaring and initializing an array. The length of the array is implicitly defined by the number of elements included within the {}. An example:
In the above example, we create an array that can hold 3 strings, already containing the values specified. pies[0] is Cherry, pies[1] is Chocolate and pies[2] is rhubarb.