Academic Java    Java Tutorial  >  Arrays

Java Arrays

An array is a sequence of zero or more elements of the same primitive or reference type, each of which is accessed by a numeric index (or offset); numbering of the elements starts at zero.

Three stages are required to make an array:

      (1) declare the name of the array
      (2) create the array
      (3) initialize the values of the array.

Code Meaning
int[] ia; (1) an array of int named ia is declared
ia = new int[3]; (2) the array of length 3 is created
ia[0]=17; ia[1]=5; ia[2]=8; (3) the array is initialized with values
int[] ib = new int[3]; (1)(2) an array ib is declared and created
int[] ic = {17, 5, 8}; (1)(2)(3) an array is declared, created, and initialized with values

The example programs to the left explain in detail the summary above.