The array and memory control of 16 lessons in crazy Java breaking through the basic skills of programmers

Source: Internet
Author: User
I. Java array Initialization

The Java array is static, that is, after the array is initialized, the length of the array is unchangeable. At the same time, the Java array is a reference variable, not an array object itself. It is similar to a pointer in C and is usually placed in the stack memory, while the array object is stored in the heap memory, so long as the array variable points to a valid array object, the program can use this array variable.

1. initialization process: allocate memory and specify the initial value;


2. Two initialization methods for the basic type array:

Static initialization: Specify the initial values of each array element. The system determines the array length;

Dynamic initialization: only the length of the array is specified. The system assigns an initial value to the array element;

Note: Do not use both methods to initialize the array!

 

3. initialization of the reference type array

The array element of the reference type array is still the reference type. Therefore, the element is stored as a reference and points to another memory, which stores the objects referenced by the referenced variable.

Ii. array usage

The Java language does not allow direct access to the data in the heap memory, so it cannot directly access the array objects in the heap memory. The program accesses the array through the array reference variable;

 

1. the array element is a variable:

No matter which type of array, its array element is actually equivalent to a common variable. After removing square brackets [] After the array type, the obtained type is the type of the array element in time;

 

2. No multi-dimensional array:

Java allows processing multi-dimensional arrays as one-dimensional arrays. During initialization, only the leftmost dimension can be initialized. At this time, each element of the array is equivalent to an array reference variable. These array elements need to be further initialized.

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.