Java review notes ---- array Summary

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.