Arrays
- Array elements are zero-based.
- Java implicitly creates an array class
for each class that is defined, and for the simple data types.
- All array classes descend from the class
Object, and mirror the hierarchy of the classes they contain.
- Arrays are static (rather than dynamic);
can't add an arbitrary number of elements to an existing array.
// Declare the array
SomeClass[] myArray;
// Create a reference for each element
myArray = new SomeClass[10];
// Or Combine the declaration and reference creation
SomeClass[] myArray = new SomeClass[10];
// Allocate the elements of the array (not needed for simple data types)
for (int i = 0; i < myArray.length; i++)
myArray[i] = new SomeClass;
Alternate syntax for declaring arrays
SomeClass myArray[];