Three ways to define arrays

Source: Internet
Author: User
1. Definition of array

Used to store a collection of data of the same type, in fact an array is a container.

Contiguous storage Unit 2. Benefits of Arrays

Automatically numbers the elements in an array from zero. Automatically give subscript, starting from zero 0-1-2-3-...... 3. Writing format

element type [] Array name = new element type []{element, element, element ...};

Format 1:int [] arr = new INT[5];

Need to manually assign value arr[0]=1;

arr[1]=2;

Arr[3]=3

arr[4]=4;

arr[5]=5;

Format 2:int [] arr = new int[]{1,3,5,7}

Format 3:int[]arr = {1,3,5,7};





4. The memory structure of the array



5. Memory characteristics of the array


(1). Because the use of the keyword new will open up the corresponding space in the heap memory, each given a different address of two arrays. When compared, the address of the two array is compared to a different




(2). This example does not use the New keyword, but the same comparison is also the address of the array;



(3). This example output is true


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.