What is an array? An array.

Source: Internet
Author: User
Tags array definition

What is an array? An array.

Array: multiple data of the same type can exist, and the data stored in the array is called an array item.

Array Index (subscript): In an array, each array item has a number. These numbers are called the index or subscript of the array, and the index (subscript) of the array) it is an int-type number. The index starts from 0 and is the number of each array item in the array in sequence.

Array code writing:

Declaration: Data Type [] variable name; data type: the type of the array item.

Value assignment: variable name = new data type [length]; Length: int type, indicating the length of the array.

The description must be consistent with the value assignment data type.

Combined writing:

Data Type [] variable name = new data type [length]

Example:

Int [] number = nwes int [5] // defines a number variable, which is an array that can store five int data types.

Default values of array items:

After an array is created, its value for each array item is the default value of the array item type.

Where:

Numeric type. The default value is 0;

Bool type. The default value is false;

Char type. The default value is \ 1;

String type. The default value is null.

Read and modify array items:

Read: The variable name [Index] retrieves the value of an array item from the specified array through the index.

Modify: The variable name [Index] = value assigns the value to the specified array.

Note: The index cannot exceed the index range.

Read array length:

Code Format:

Variable name. Length

The return type is int.

Array initializer:

Example:

String [] strs = new string [3] {"a", "B", "c "}

The preceding example is simplified as follows:

String [] strs = {"a", "B", "c"]

Note: Simplified writing can only be used in array definition statements.

You do not need to specify the array length when using the array initialization tool. The compiler will automatically fill in the array length according to the number in the initialization tool.

I don't understand many things for beginners. Thank you for your help.

Related Article

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.