-
Array format Definition
Int [] arr1; int[] arr1; // Define a variable of type int. The variable name is arr1 array int arr2[];Copy the code
-
Static initialization
// Format: data type [] variable name = new data type []{data 1, data 2, data 3... } int[] arr1 = new int[]{1,2,3}; // Simplified format: data type [] variable name = {data 1, data 2, data 3... } int[] arr2 = {1,2,3}; [] Variable name = {{data 1, data 2, data 3... },{data 1, data 2, data 3... }} int[] arr3 = {{1,2,3},{1, 3}};Copy the code
-
Dynamic initialization
Int [] arr = new int[3]; System.out.println(arr); // [I@3b22cdd0 System.out.println(arr[0]); // 0 System.out.println(arr[1]); // 0 System.out.println(arr[2]); // 0Copy the code
-
The data is very convenient
Int [] arr = {1,2,3}; System.out.println(arr[0]); System.out.println(arr[1]); System.out.println(arr[2]); For (int I = 0; i < arr.length; i++) { System.out.println(arr7[i]); } // foreach convenience for (int I: arr) {system.out.println (I); }Copy the code