Home Java SCJP SCWCD Servlet Submit News Contact Us Site Map


Over 500 magazines for free (including Oracle Magazine)!

Yes all of them are FREE. You can subscribe to ALL of them.
Click here to apply today!

Home > Java > Java Articles

Java Array

Java Array is a fixed number collection of elements having same data type. In java array is an object. A java array can have primitives as well as object references.

Each and every element in an array is identified through a non negative number called index. The size of an array is fixed and can not be changed

An array has a final field called length, which denotes the number of elements an array can accommodate. The first element is always at index 0 and the last element at length – 1.

 

Declaring a Java array variable

An array can be declared using following syntax.

<type> [] arrayName ;

or

<type> arrayName [];

Here type can be any primitive or reference type.

Note: Array size is not defined here. This array variable can be assigned to an array of any length.

Declaring an array variable does not actually create an array nor allocate any memory. It just creates a variable which can hold reference to the array.

An array variable declared as a member variable will be automatically initialized to default value null, while local array variable not.

 

Java Array Creation >>


Home Java SCJP SCWCD Servlet Site map