What is an array: a heap of data of the same type (a set of related variables)
Definition syntax:
- Declare and open an array
Data type array name [] = new data type [length];
- Distribution complete
- Declaring an array: Data type array name [] = null;
- Open array: Array name = new data type [length];
Public classTest2 { Public Static voidMain (String args[]) {intArr[] =New int[3]; arr[0] =1; arr[1] =2; arr[2] =3; for(intI=0;i<3; i++) {System. out. println (Arr[i]); } }}
Memory Analysis:
- Declare and open an array
2. Distribution Complete
Array Memory Reference
An array is a reference data type
Public classTest2 { Public Static voidMain (String args[]) {intArr[] =New int[3]; arr[0] =1; arr[1] =2; arr[2] =3; intArr_tem[] =arr; arr_tem[0] = -; for(intI=0;i<3; i++) {System. out. println (Arr[i]); } }}//output to
- 2 3
All of the above methods are dynamic initialization of arrays, which are the first space to be set up for an array and then assigned. Here, you will be contacted with the previous method of constructing (and then creating the default value when instantiating the object), and the two static initialization methods of the array are described below.
Simple method: int arr[] = {value, value, value ...} Try not to use
Complete method: int arr[] = new int[] {value, value, value ...}
Public class test2 { publicstaticvoid main (String args[]) { int New int [] {A-I}; int arr_tem[] = arr; arr_tem[0] = +; for (int i=0;i<3;i++) { System.out.println (arr[i]); }}}
Java Basic Learning Path (v) definition of an array