Create an array Summary
Method description syntax
Declare only the array data type [] array name;
Description and Creation
Use the keyword new to declare
And allocate space for array elements
Data Type [] array name = new data type [array length];
Declaration, creation, and initialization
Declare an array and allocate memory to it
And assign the initial value to the element
Data Type [] array name = {value 1, value 2, value 3,..., value n };
Data Type [] array name = new data type [] {value 1, value 2, value 3,..., value n };
Default Value of array elements
Basic Type
Default Value
Boolean
False
Char
'\ U000000' (null)
Byte
(Byte) 0
Short
(Short) 0
Int
0
Long
0L
Float
0.0f
Double
0.0d
The java. util. Arrays class provides many common methods to operate Arrays, such as sorting and querying. The sorting method sort () sorts the specified array. The query method binarySearch () performs binary search on the sorted array, if a specified value is found, the position of the value is returned (array subscript ). Quick sorting is used in the sort () method. The syntax for sorting elements in an Array is Array. sort (Array name ). Note: The sort method of the Array class sorts the elements in numbers in ascending order. Here, you do not need to create an Array instance to call the sort method because sort is defined as a static method.