My java--Array (3)

Source: Internet
Author: User

Arrays and enhanced for statements

In JDK 1.5, the For statement is enhanced so that it is easier to iterate over the elements of an array

Basic format: It uses a type name in the For statement a variable name a colon an array name

int []num={1,2,3,4,5}

for (int n:num) {

SYSTEM.OUT.PRINTLN (n);

}

Such a traversal has to be made with elements that cannot change the element

Copying of arrays

The System.copyarray () method can be used to copy an array whose format is

System.arraycopy (Object src,int src_position,object dst,int dst_position,int length)

He copies the array from SRC to DST where the copy element is src_ the first src_position element of SRC, and the number of copy elements in the dst_position position of DST is length

Note: The method copies only the elements if the array element is a reference variable and only the copy reference does not copy the object entity

* Basic types (primitive type)

A variable of the base data type contains a single value whose length and format conform to the requirements of the data type to which the variable belongs, which can be a number, a character, or a Boolean value, such as an integer value of 32-bit binary complement format data, and a character type whose value is 16-bit Unicode character formatting data, and so on.

* Reference types (reference type)

The value of a reference variable is different from the base type variable, which is a reference (address) to the memory space. The memory pointed to holds a value or set of values represented by the variable.

References are referred to in other languages as pointers or memory addresses. Unlike other programming languages, the Java language does not support displaying the use of memory addresses, but must be accessed through variable names for a memory address.

My java--Array (3)

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.