An array of Java Foundations (vi)

Source: Internet
Author: User

An array variable is a reference type, and an array can be considered an object, and each element in the array is equivalent to the member variable of that object.

The elements in the array can be any data type, including the base type and the reference type.

When declaring an array in the Java language, you cannot specify its length (the number of elements in the array), when an array is declared, only one reference variable is created, the variable exists in the stack, and no memory is allocated in the heap, at which point the value of the reference variable is null.

The creation of the array object, the type of the new array element [number of elements of the array], when the array object is created, the memory is allocated in the heap, so you can also specify the number of array elements, and assign the heap memory address of the object to the array reference variable. When created, the array element is not initialized, which is the default value, such as an int array, with a default value of 0.

element is an array of reference data types, and each element in the array needs to be instantiated.

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/92/C8/wKiom1kC636wAmcGAACowEx98po757.png-wh_500x0-wm_ 3-wmp_4-s_1261885779.png "title=" reference. png "alt=" wkiom1kc636wamcgaacowex98po757.png-wh_50 "/>

A two-dimensional array can be thought of as an array of elements, and the declaration and initialization of multidimensional arrays in Java should be carried out in order from high to low dimensions. Array names in two-dimensional arrays represent high-dimensional reference variables, and array names [high-dimensional subscripts] represent low-dimensional reference variables, array names. Length indicates the number of elements in the high dimension, and the array name [high-dimensional subscript].length represents the number of elements in the lower dimension.

Copy of the array:

static method using the Java.lang.System class: public static void Arraycopy (object src,int srcpos,object dest,int destpos,int length), src original array , the copy starts from the srcpos position of the element group, copies the length elements to the target array dest, and the copy starts at the Destpos position of the target array.


This article is from the "one step, one step" blog, please be sure to keep this source http://summerflowers.blog.51cto.com/5202033/1920489

An array of Java Foundations (vi)

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.