Java array,
Array concept:
Allocate multiple consecutive buckets to a computer
Using a bucket is essentially a value.
Syntax for defining Arrays:
How to obtain the continuous storage space:
Dynamic definition: simultaneous definition assignment:
Data Type [] array name = new data type [length]
First define and then assign values:
Data Type [] array name;
Array name = new data type [length];
Static definition: complex syntax:
Simultaneous Value assignment:
Data Type [] array name = new data type [] {value, value ,........};
First define and then assign values:
Data Type [] array name;
Array name = new data type [] {value, value ,........};
Abbreviations:
Simultaneous assignment of definitions: (commonly used)
Data Type [] array name = {value, value ,........};
First define and then assign values:
Syntax not allowed
Recognition array:
Define an array: int [] arr = new int [6];
Int []: Data Type: int type array, type!
Arr: array name: variable: array is the reference data type, and the address is saved!
6: array Length
The value stored in each bucket in the array: Value: element ..
Stored Value Syntax:
Array name [index value] = value;
Value Syntax:
Array name [index value];
Note:
Array name: it is essentially a variable, storing the address value
Data Type []: the data type is an array type, indicating the array type of the corresponding data type (when it is dynamically defined, the default value of int is 0, and the default value of String is null)
The length of the static definition is determined based on the number of values.
Features:
1. The index value starts from 0. The maximum index value is 1 less than the length.
2. Data type, which limits the array storage space and can store the type of stored values
3.The default value is allocated based on the data type.
The default value of the referenced data type is null.The default value of the basic data type is 0.
4.Once the array is defined, its length remains unchanged.
Stack analysis: JVMMemory diagram:
STACK: save as a variable. Array name and address
Heap: everything new is in it
Purpose: analyze the reference data type... the learned class, often using Stack analysis.
Array FAQ:
1. array out-of-bounds: When the value or query value index size is greater than or equal to the length of the array
2. null pointer exception int [] arr = null; arr. length is equivalent to null. length. Other data types will also appear
3. return does not know how to write the return value.
Two-dimensional array (understanding ):
An array stores a one-dimensional array: Three-dimensional, four-dimensional array is similar
Syntax defined by two-dimensional arrays:
Dynamic definition: Data Type [] [] arr = new data type [length 1] [length 2];
Length 1: in a two-dimensional array, the number of one-dimensional arrays is saved.
Length 2: the length of a one-dimensional array in a two-dimensional array
Static definition: array type [] [] arr = {1, 2, 3}, {4, 5, 6}, {7, 8, 9 }};
Value transfer value reference:
Value Transfer: the formal parameter type is the basic data type.
Value reference: The format parameter type is the reference data type.
For basic data, the value is passed. When a method is called, the actual parameter passes its value to the corresponding form parameter. The form parameter only initializes its own storage unit content with the actual value of the parameter.
Reference data: the reference to the value is passed !, The address value is passed. Method call is: the actual parameter is an array. In this case, the actual parameter and the form parameter point to the same address. During method execution, the operation on the form parameter is actually an operation on the actual parameter.