Home >Java >javaTutorial >What are the methods defined in java arrays?
1. Description
An array is an ordered collection of similar data. Arrays describe several data of the same type, arranged and combined in a certain order.
In these factors, each data is called an array element, and each array element can be accessed through a subscript.
2. Three definitions
(1) applies to arrays that do not use initialization. When the array is particularly long, it is not initialized and the values are default values.
Data type [] array name = new data type [array length]
For example
int[] a = new int[3];
Create an array of type int with a length of 3
(2) Suitable for direct initialization of arrays.
Data type [] Array name = {1,2,3}
The length of the array is determined by the number of elements in the curly brackets
int[] arr = {1,2,3};**
(3 ) Anonymous arrays are suitable for transferring parameters directly to methods.
Grammar
new 数据类型[] {1,2,3}
The above is the detailed content of What are the methods defined in java arrays?. For more information, please follow other related articles on the PHP Chinese website!