- an array that is not initialized to an allocated value has the
special value null, which cannot be indexed
- initializing the array (the container) is different from
initializing each of the elements: the array must be initialized
first, then the elements
- initializing array elements one by one can be as follows
coinNames[4] = "half";
This could be done within a loop, e.g.
a[i] = i*7;
- or all can be initialized and allocated at once, e.g.
double [] x = {1.0, 2.71, 3.14, 4.0};
- the length of an array is one more than the highest usable index
int i = 0;
while (i < x.length) {
x [i] += 1.0;
}
- arraycopy can be used to copy elements from one
existing array to another existing array:
System.arraycopy(sourceArray, sourcePos,
destArray, destPos,
elementCount);
all the element positions must be valid, specifically:
- sourcePos through
sourcePos + elementCount - 1 on sourceArray, and
- destPos through
destPos + elementCount - 1 on destArray