Meaning: A data type that consists of variables of the same type.
One-dimensional arrays
2 steps to use an array:
(1) declares an array (2) to allocate memory to the array.
Declaration Format 1:
Data type array name [];//Declare one-dimensional array such as: int arr1[];
Array name = new data type [number]; Allocate memory to arrays such as: Arr1=new int[5];
Declaration Format 2:
Data type array name [] = new data type [number]; such as: String num[]=new string[5];
Take the length of the array:
Array name. length
Initial value assignment of an array
Declaration format:
Data type array name [] = {Initial value 0, initial value 1, ..., initial value n}; such as: int num[]={7,98,66,64,66};
Int Num[]=new int[4];
num[0]=55;
num[1]=34;
...
num[4]=45;
Array-related API methods
System.arraycopy method
System.arraycopy (source,0,dest,0,x): The meaning of the statement is: Copy the source array from the subscript 0 starting from the X element to the target array, from the target array of subscript 0 corresponding to the location to start access.
Arrays.sort (array name)
Sorting elements in an array
Two-dimensional arrays
Declaration format:
1. Array name of data type []; such as: int num[][];
2. Array name = new data type [number of rows] [number of columns]; for example: Num=new int [2][3];
3. Data type array name [] = new data type [number of rows] [number of columns];
4. Data type array name [] = {{No. 0 row initial value},
{1th row of initial value},
...
{nth row of initial value},
};
Note: The number of elements in each row of a two-dimensional array can be different.
Gets the number of rows in a two-dimensional array and the elements of a particular row
Array name. length//Gets the number of rows in the array
Array name [index of row].length//Gets the number of specific line elements
2. Java Array