1. Concept
a collection of the same type of data. The array is actually a container .
2. Benefits of Arrays
The elements in the array can be automatically numbered starting with 0, allowing them to be manipulated.
3. format 1:
element type [] array name = new element type [ element number or array length ];
int[] arr = new int[5];
4. format 2:
element type [] array name = new element type []{ element, element, ... };
I nt[] arr = new int[]{3,5,1,7};
int[] arr = {3,5,1,7};
Element type [] array name = new element type [ element number or array length ];
int x = 4;//a data. NEW: The keyword used to create the entity int[] arr = new INT[3]; A variable that defines an array of type int elements arr,//creates an array entity with the New keyword that can store 3 elements of type int.
Allocation of arrays in memory
Please see attachment
FAQ for Arrays
Array Operations FAQ. 1.//arrayindexoutofboundsexception: Array angle label out of bounds exception, occurs at runtime int[] arr = new INT[3]; System.out.println (Arr[3]);. This exception occurs when a corner label that does not exist is accessed. 2.//nullpointerexception null pointer exception. arr = null; System.out.println (arr[1]); This exception occurs when the reference (ARR) does not have any entities pointing, and its action entity is also being used.
For example, the common operation of an array - the maximum value
Public static int getmax (Int[] arr) {&NBSP;&NBSP;&NBSP;&NBSP;//1, defines a variable and records a larger value. int max = arr[0];//initialization is an array of any element //2, traversing an array. for (int x=1; x<arr.length ;x++ ) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//3, make a judgment comparison. if (Arr[x]>max) max = arr[x]; } return max; } //the second maximum value. PUBLIC&NBSP;STATIC&NBSP;INT&NBSP;GETMAX2 (Int[] arr) { int maxindex = The 0; //is initialized to any of the corner labels in the array. for (int x=0; x<arr.length ;x++ ) { if (Arr[x]>arr[maxindex]) {&NBSP;&NBSP;&NBSP;&Nbsp; maxindex = x; }}
Java Syntax Basics-arrays