Fourth chapter arrays and methods

Source: Internet
Author: User
Tags shallow copy

1. Declaring and allocating memory for one-dimensional arrays
Array type array name [] = NULL//declaration one-dimensional array
Array name = new array type [length]//Allocate memory to array
Array type [] array name = NULL//declaration one-dimensional array
Data type array name [] = new data type [NUMBER]//Declare array while allocating memory
2. Get the length of the array
Array name. Length--Returns an int type of data
3. Complete array sorting using Java class Library
Java.util.Arrays.sort (array name)

4. Copying of arrays in Java

The copy operation of the Java array can be divided into deep copy and shallow copy, simple deep copy, can copy the object's value and object's content; Shallow copy refers to the copy of the object reference.

You can use System.Array () to copy an array.

For a one-dimensional array, this copy property value is passed and the modified copy does not affect the original value. When an object is stored in a two-dimensional or one-dimensional array, the copy result is one-dimensional reference variable passed to the copy of the one-dimensional array, and when the copy is modified, the original array is affected.

The function prototypes for system.arraycopy are:

public static void Arraycopy (Object src, int srcpos,object dest,int destpos,int length)

Where: src represents the source array, Srcpos represents the starting position where the source array is to be copied, DESC represents the destination array, Destpos represents the starting position of the destination array to be copied, and length indicates how long to copy.

5, JAVA----variable parameters

Definition format for variable parameters

Return value type method name (Type ... Parameter name) {}

6. JAVA----foreach Output

Mainly for the convenience of array output

For (data type variable name: array name) {

........

}

Fourth chapter arrays and methods

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.