4. Arrays

An array in Java is a real object with a runtime representation. You can declare and allocate arrays of any type, and arrays of arrays (to get multi-dimension arrays). But arrays do not belong to a Java class, they are special objects.

int[] foo;

4.2. Initialization:

Like any other reference variable, after declaring an array memory has to be allocated to it. Arrays can contain any legal Java data type:

foo= new int[40];

4.3. Out of bounds:

Java arrays automatically test for index out of bounds errors. It throws the IndexOutOfBoundsException if one happens.

4.4. The length property:

Length is a property provided for all Java arrays, it retrieves the current length of the array:

System.out.println(foo.length);

Audio in Portuguese