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;
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];
Java arrays automatically test for index out of bounds errors. It throws the IndexOutOfBoundsException if one happens.
Length is a property provided for all Java arrays, it retrieves the current length of the array:
System.out.println(foo.length);
Copyright © 1998-2009 Dilvan Moreira