1. Declaring Array variables
Elementtype[] Arrayrefvar;
2. Creating an array
1) After declaring an array variable, it does not allocate any space to the array in memory, but creates a logarithmic group
The storage location of the reference. If the variable does not contain a reference to an array, then the value of the variable is null
2) Only the array has been created, can it be assigned an element
3) Statement: Arrayrefvar = new Elementtype[arraysize];
4) consolidated Declaration and creation
elementtype[] Arrayrefvar = new Elementtype[arraysize]
5) Default Value
The default value is given when the array is created (different from the C language)
The default value of type 0,char is ' \u0000 ', and the Boolean default value is False
4. Accessing array elements and initialization syntax is the same as the C language
5.foreach Cycle
for (double e:mylist) {
System.out.println (e);
}
6. Copying of arrays
1) cannot be copied directly with =, so only the reference value is copied.
2) Three ways:
1) Loop statement
2) system.arraycopy (Sourcearray,srcpos,targetarray,tarpos
, length)
The Arraycopy method does not allocate memory to the target array!
3) Clone method
7. Array passed to method
1) The reference value is passed and the array outside the method is changed
2) You can return an array using methods
8. Variable length parameter list
1) typeName ... elementname
2) You can only specify a variable-length parameter in a method, and must be the last parameter
3) Java treats variable-length parameters as arrays
Tips
You can use variables as the length of an array when you define an array in Java
double[] numbers = new Double[n];
9. Two-dimensional array
1) Disclaimer
data type [] array name;
2) Create
Array name = new data type [Rows][cols];
3) A two-dimensional array is also a one-dimensional array, and each of its elements is an array of one
Two-dimensional arrays can have different lengths of rows
Beginner java--Array