Java array summary

An array is a common data structure used to store multiple data. Unlike a linked list, it creates a continuous memory space in the heap at one time, and each array element occupies the same memory size. The array can be accessed through the array element index. elements, so the array element types must be the same. Arrays are also objects, which manipulate the array by pointing to the memory occupied by the elements in the array through the array reference variable. Array definition refers to defining a reference variable and does not open up memory space. But it doesn't point to a valid piece of memory. Array initialization means creating a memory space for the array and pointing to it with an array reference variable. Array initialization is divided into static initialization and dynamic initialization. Static initialization means that the initial value of each element is specified by the developer: int[] intArr; intArr = new int[] {1,2,3,4,5}; Or define and initialize together: int intArr = new int[]{1,2,3,4,5}. Dynamic initialization only defines the length of the array, and the compiler assigns a default value to each element. Such as: Object obj = new String[5]. However, it is not possible to define the length of the array and define the value of the array elements, which may be to prevent the two from being inconsistent.

Arrays are actually data structures. Although Java does not require programmers to understand memory operations like C++, but if you understand its memory operations, you will have a better understanding of two-dimensional and three-dimensional arrays. The principle is also one-dimensional arrays, but the memory pointed to by the array references It's just a reference. For example, class 301 is a reference variable that points to 30 students in the class, and 30 students are also a reference variable, each of which points to a specific student (name, age, gender).

Java8 provides the tool class Arrays, and the static methods in it directly manipulate the array. Such as search, copy, sort and so on.

Guess you like

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