1. Definition of array:
Arrays can be divided into one-dimensional arrays, two-dimensional arrays, and multidimensional arrays. The one-dimensional array is defined in the following two ways:
Type[] Arr_name;
Type arr_name[];
Two-dimensional arrays are defined in the following ways:
Type[] [] arr_name;
Type arr_name[] [];
A multidimensional array can specify the corresponding number of dimensions based on the dimension []
Int[] arr1;
String[] ARR2;
float arr3[];
String[] [] ARR4;
2. Initialization of the array:
The initialization of an array has the following two ways
Static initialization
Static initialization refers to specifying the contents of an array element while defining, with the sample code as follows:
Int[] arr1 = {1,2,3,4,5};
String[] arr2 = {"Tom", "Rose", "Sunny"};
String[] Arr3 = {{"Tom", "American"},{"Jack", "England"},{"John", "the" "", "};
Dynamic initialization
Dynamic initialization is defined by first opening the specified size of storage space through the new keyword, and then specifying the contents in the array
int[] arr1 = new int[2];
Arr1[0] = 10;
ARR2[1] = 20;
arr3[2] = 30;