Java Reference
In-Depth Information
for (int i = 0; i < ia.length; i++)
System.out.println(i + ": " + ia[i]);
An array with length zero is said to be an empty array. There is a big
difference between a null array reference and a reference to an empty
arrayan empty array is a real object, it simply has no elements. Empty
arrays are useful for returning from methods instead of returning null .
If a method can return null , then users of the method must explicitly
check the return value for null before using it. On the other hand, if
the method returns an array that may be empty, no special checking is
needed provided the user always uses the array length to check valid
indices.
If you prefer, you can put the array brackets after the variable name
instead of after the type:
int ia[] = new int[3];
This code is equivalent to the original definition of ia . However, the first
style is preferable because it places the type declaration entirely in one
place.
7.4.1. Array Modifiers
The normal modifiers can be applied to array variables, depending on
whether the array is a field or local variable. The important thing to
remember is that the modifiers apply to the array variable not to the
elements of the array the variable references. An array variable that is
declared final means that the array reference cannot be changed after
initialization. It does not mean that array elements cannot be changed.
There is no way to apply any modifiers (specifically final and volatile )
to the elements of an array.
 
Search WWH ::




Custom Search