Friday, September 3, 2010

JAVA array initialization

the array name can be represented with subscript array elements. The first element is an array subscript to O elements, such as points [0]. The last element of the subscript for the length of a 1, such as points [points.1ength 1 1]. When you create an array, each element is initialized. As previously created character array s, each of its value is initialized to O (\ 0000). The array of points ...

Subscript array name with an array of elements can be expressed. The first element is an array subscript to O elements, such as points [0]. The last element of the subscript for the length of a 1, such as points [points.1ength 1 1].

When you create an array, each element is initialized. As previously created character array s, each of its value is initialized to O (\ 0000). The array of points of each value is initialized to null, that it not point to a real Point object. In the assignment points [o] = New Point ();, the system creates a real Point object, and so the first element of the array point to it.

Note: includes an array of elements, including the initialization of all variables. From the perspective of system security are essential to any variable can be used without initialization state. Compiler can not check the array element initialization conditions.
Java allows to create an array with initial value, such as the example:

String names [] = ( 
"Georgianna", 
"Tenn", 
"Simon", 
"Tom" 
); With four names array initialization string constants, such mode is called static initialization, it is equivalent to:


String names []; 
names = new String [4]; 
names [0] = "Georgianna"; 
names [1] = "JEN"; 
names [2] = "Simon"; 
names [3] = "Tom";

Static initialization can be used for any element type, the location of the initial value of each block corresponds to each element of a reference.

No comments:

Post a Comment