In Java, the array is regarded as an object, and length is the attribute of the array rather than the method.
1. One-dimensional array
Definition: datatype [] arrayname; or
Datatype arrayname []; the first type of Java habits is recommended.
The array definition only declares the variables of the array type. In fact, the array does not exist in the memory. To use the array, you need to apply for space for the array:
Arrayname = new datatype [arraysize]
Example:
Int [] intarray;
Intarray = new int [5];
It can also be completed in one step
Int intarray [] = new int [5];
Default Value during initialization
Byte short int long 0
Float double 0.0
Char \ 0 (Space)
Boolean false
Object Type null
Two-dimensional array (array)
Definition:
Datatype [] [] arrayname; or
Datatype arrayname [] [];
Create:
Int array [] [] = new int [4] [6]; or
// Contains two one-dimensional arrays
Int array [] [] = new int [2] [];
Array [0] = new int [4];
Array [1] = new int [5];
Note that the second dimension is different.
Initialization:
Direct initialization:
Int array [] [] = {1, 2, 3}, {5, 6}, {6, 9 }};
Note that array [1] has only two numbers, 5 and 6, and is not the default value.
Initialize as an array
Int array [2] []; // defines the high dimension as 2.
Int row0 [] = {1 };
Int row1 [] = {2, 3, 5 };
// The array in Java is regarded as an object, and the object name can be assigned a value. Note that array [0] is the name of a one-dimensional array.
Array [0] = row0;
Array [1] = row1;
Array copy arraycopy Method
System. arraycopy (Object SRC, int src_position, object DST, int dst_position, int length );
Copy the length element from src_position of SRC to dst_position of DST.