Array of common Java APIs (with analysis and examples) _05

An array is a collection of the same data type , and an array is actually a container.

Arrays automatically number the elements in the array starting from 0, so that as long as the subscript index is provided, the elements in the array can be efficiently and randomly read.

The Java language uses the new operator to create arrays. It is recommended to use dataType[ ] var instead of dataType var[ ] to create arrays, which can separate the data type from the variable name and has a better code style. To create an integer array of length 5: int[ ] num = new int[5];

In the array operation, the name of the array is stored in the stack memory, and only the space in the stack is opened up. The array can never be used, and only the heap memory pointed to can be used. To open up a new heap memory space, the new keyword must be used , and then the right to use the memory is given to the corresponding stack memory, and a heap memory space can be pointed to by multiple stack memory spaces at the same time, for example, a person can have multiple Name, person is equivalent to memory, name is equivalent to stack memory

Operates on array elements in the format arr[ index ].

The array comes with a length property , indicating the length of the array; the array also has several methods inherited from the Object class.

A foreach loop can traverse an array without indexing.

for (dataType element : arr)
{
     System.out.println(element);
}
The Java.util.Array class can easily manipulate the array, such as calling the sorting and searching algorithms of the Array class to process the array, and all the methods it provides are static.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325691932&siteId=291194637