Find their basic knowledge is not solid enough, slowly review!
Array creation:
Mode one: type[] Variable name = new type[element number]; -such as: int[] a = new int[10];
Mode two: type variable name [] = new type[element number]; -such as: int a[] = nwe int[10];
Way three: type[] a= New type[]{initialization value, comma delimited}--such as: int[] a=new int[]{1,2,3}
The initialization value cannot be defined at the same time-for example: int[] a=new int[3]{1,2,3}
Multidimensional Arrays:
Multidimensional arrays, the first dimension must be specified, and must be defined by high dimensional to the low dimension--for example: int[][] a=new int[][3];
Type[][] A=new type[2][3];
Type a[][]=new type[3][2];
Int[][] A=new int[][]{{1,2,3},{2,2},{3,2,1}}
Length
Read-only member length is part of an array object and is the only field or method that can be accessed. [] is the only way to access an array object.
Multidimensional arrays, length can only calculate the first dimension length.
Assignment references:
When the Java array is initialized, it has only a reference to the array and does not allocate storage space to the arrays. Therefore, replication between arrays cannot be simply assigned with "=" because the same object is being manipulated.
The results show:
Change the value of arrayb[0], change the reference array, so we output ARRAYA[0], in fact, and Arrayb[0] the same.
Array replication:
1.for Cycle
2.system.arraycopy (SRC, Srcpos, dest, destpos, length);
SRC: source array;
Srcpos: The starting position of the source array to be copied;
Dest: an object array;
Destpos: The starting position of the destination array placement;
Length: The size of the copy.
--system.arraycopy (arraya,0,arrayb,0,1), which is faster than a for loop, but the object array is simply a copy reference and will not have two copies.
and System.arraycopy () does not automatically wrap and unpack, require arrays of the same type, or convert to the same type.
Array comparison:
Arrays.equals (Arraya, Arrayb); equality Condition: The number of array elements is equal, the corresponding elements are equal
Multidimensional array comparison: Arrays.deepequals (Arraya, Arrayb); two arrays must be of the same type
Java Array Learning Notes