15-07-08 Array

Source: Internet
Author: User

Array: Is the space to store the same type of data in memory continuously

Because you need to store large amounts of data of the same type in real-world applications, you have an array

Definition of array: data type [] array name =new data type [length];

Example: int [] a = new int [10];

data type [] array name =new data type []{value, separated by commas};

Example: int [] b = new int []{1,2,3,4,5};

Array assignment and value: use subscript to manipulate each element in the array

Assignment: array name [subscript] = value;

Value: array name [subscript];

Note: The index of an element in an array starts at 0, and the maximum subscript value is less than the length of the array 1

The benefits of arrays:

1. Define multiple spaces for storing data at once

2. Can be used in conjunction with a For loop, using the loop variable as the subscript for the data

One-dimensional arrays:

①int [] n = new int [5];     N[0] = 1;     N[1] = 2;   n[2] = 3;    n[3] = 4; N[4] = 5;

②int[] n = new int[] {1,2,3,4,5};

Two-dimensional array: int[,] a =new int [4,2];

15-07-08 Array

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.