I. Java array Initialization
The Java array is static, that is, after the array is initialized, the length of the array is unchangeable. At the same time, the Java array is a reference variable, not an array object itself. It is similar to a pointer in C and is usually placed in the stack memory, while the array object is stored in the heap memory, so long as the array variable points to a valid array object, the program can use this array variable.
1. initialization process: allocate memory and specify the initial value;
2. Two initialization methods for the basic type array:
Static initialization: Specify the initial values of each array element. The system determines the array length;
Dynamic initialization: only the length of the array is specified. The system assigns an initial value to the array element;
Note: Do not use both methods to initialize the array!
3. initialization of the reference type array
The array element of the reference type array is still the reference type. Therefore, the element is stored as a reference and points to another memory, which stores the objects referenced by the referenced variable.
Ii. array usage
The Java language does not allow direct access to the data in the heap memory, so it cannot directly access the array objects in the heap memory. The program accesses the array through the array reference variable;
1. the array element is a variable:
No matter which type of array, its array element is actually equivalent to a common variable. After removing square brackets [] After the array type, the obtained type is the type of the array element in time;
2. No multi-dimensional array:
Java allows processing multi-dimensional arrays as one-dimensional arrays. During initialization, only the leftmost dimension can be initialized. At this time, each element of the array is equivalent to an array reference variable. These array elements need to be further initialized.