An array is a variable, a set of data that stores the same data type is declared a variable is a block of space in the memory space to declare an array is a contiguous array of spatial arrays in memory space fixed, avoid array out of bounds array is statically allocated memory space, All elements are stored in a contiguous set of storage units, once assigned, cannot be changed, is not easy to expand, the array is easy to find and modify, and is not conducive to insertion and deletion. Using arrays: ① declaring arrays ② allocating space ③ assignment ④ processing data in Java array definitions to specify the length. data type [] Array name = new data type [array length]; data type [] Array name = new data type [number of rows] [number of columns]; Gets the length of the array = array name. length; Gets the element in the array = array name [subscript]; &NBSP;&NB sp; element subscripts from 0 to length-1 assign values to arrays: array name [corresponding subscript] = assigned value; array sort: ① Select sort: Let each number in the array, followed by The subsequent number is compared, and the position is exchanged if the previous number is greater than the subsequent number. The first number is compared to the number in the back, and the smallest number is the first when the comparison is completed. for (int i= 0; i< arr.length-1; i++) { & nbsp for (int j=i+1;j<arr.length;j++) { int temp; if (arr [i] > Arr[j]) { TEMP = arr[i];& nbsp Arr[i] = arr[j]; ARR[J] = temp; } } } ② Bubble Sort: Two adjacent numbers are compared, the first wave compares, the largest number is at the end. (after each comparison, the following number decreases a comparison) for (int i = 0; i < arr.length-1; i++) { &nbs p; for (int j = 0; J < Arr.length-1; J + +) { &nbs P if (Arr[j] > arr[j+1]) { Int temp = arr[j]; & nbsp; ARR[J] = arr[j+1]; Arr[j+1] = temp; } } }
Java Basics--array review