-
An array is an ordered list of values, which are
of the same type. That type can be primitive types or reference types (class
or interface).
-
Arrays are objects. Array types are reference types.
-
Arrays are of fixed size and are always bound checked.
-
The length of array: ia.length
-
Index starts from 0. An array of size N is indexed
from 0 to N-1
-
Examples:
int[] ia = new int[3];
ia[0] = 1; ia[1] = 2; ia[2] = 3;
int ia[] = new int[3];
ia[0] = 1; ia[1] = 2; ia[2] = 3;
int[] ia = { 1, 2, 3};
float[][] mat = new float[4][4];
for (int y = 0; y < mat.length;
y++) {
for (int x = 0; x < mat[y].length;
x++)
mat[y][x] = 0.0;
}
-
Array as parameters
-
An entire array can be passed to a method as a parameter
-
Like any other object, the reference to the array
is passed, making the formal and actual parameters aliases of each other
-
Changing an array element in the method changes the
original
-
Arrays of objects
-
Command line arguments
-
Example: CD.java,
CDCollection.java,
Tunes.java