An array of

concept

An Array is used to store multiple collections of the same type of data.

To get the value of an element in an array, you can get it from the subscript of the element, which starts at 0.

Create an array

Generally divided into dynamic initialization and static initialization

Int [] a = new int[5];

Create a new int[] with length 5

The default value for each newly created array is 0. The default value for data of type int is 0

Store the array’s address value in the variable a

Int [] a ={1,2,3,4,5,6,7,8};

Int [] a =new int[]{1,2,3,4,5};

Array length

The length attribute gets the length of the array

Once an array is created, its length is immutable

Allows arrays of 0 length

Array traversal

Accessing the position of the array from beginning to end.

Knowing where to start and where to end, we usually use a for loop to traverse the array, but if the traversal goes beyond the maximum value of the index, we get an exception where the index goes out of bounds

The array utility class Arrays

The Arrays. ToString (array)

A comma concatenates the data in the array into a string.

Format: [10, 14, 20, 46, 51]

The Arrays. Sort (array)

To sort the array, for the basic type of array using the optimized quicksort algorithm, high efficiency.

For arrays of reference types, an optimized merge sort algorithm is used.

CopyOf (Arrays, new length)

Copies the array into a new array of the specified length.

The new array is longer than the original array, equivalent to copying, and increasing the position. Array size enlargement

The length of the new array is smaller than the original array, which is equivalent to truncating the previous part of the data. Array size