11th days: array, 11th days group

Source: Internet
Author: User

11th days: array, 11th days group

 

1: How to save multiple data: Array

2: Array

2.1: stores multiple data of the same type. That is, it can represent multiple basic data types or multiple referenced data types, but the array represents the same type of data, that is, the array cannot contain multiple data types, for example, an array of the int type cannot contain data of the double type. The data address in the memory is continuous.

Feature: when creating an array, you must determine the size of the array. The size of the created array cannot be changed. This is also the confirmation of the array.

2.2: Syntax: []

Data Type [] array name.

Type [] array name = new type [array size]; array name = {param1, param2 ...}

Type [] Name = {param1, param2 ,...};

Type [] Name = new type [] {param1, param2 ...};

Note: int [] array = new [5];Indicates that the size of the array is 5.And the subscript is from 0So the maximum subscript is 4.; Calculation method: array. length-1,Note that the length of the array. lengthIs an attribute rather than length ()One Method

 

2.3: array Traversal

1: Use a loop

2: Use an enhanced for loop. In this way, only the values in the array can be obtained, but the subscript of the array cannot be used.

For (data type variable name: array to be traversed)

{Enter the variable name directly}

1         int [] b = {1,2,3,4,5};2         for (int i : b) {3             System.out.println(i);4         }    

 

 

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.