Some common operations for arrays in Java

Source: Internet
Author: User

An array is a data structure used to store a collection of values of the same type. Each value in the array can be accessed through an integer subscript.

Common actions are as follows:

    1. declaring an array;
    2. initialization of arrays;
    3. View array length;
    4. For Each loop;
    5. Array copy;
    6. Array sorting;
    7. Converts an int array to a string;
    8. two-dimensional array;

1. Declaring arrays

Syntax: data type [] array name;

Or a data type array name [];

2, array initialization

3. Get the array length

4. For Each loop

foreach is not a keyword in Java, it is a special simplified version of A for statement, which is simpler and easier to iterate through arrays and collections.

Syntax: for (element type element variable: Traversal object) {

Execute code

}

5. Array copy

If you want to copy all the values in an array to a new array, use the Copyof method of the A soft Ayung class:

6. Array sorting

Syntax: Arrays.sort (array name);

7. Converting an int array to a string

8, two-dimensional array

1. Declaring arrays and allocating space

data type [] Array name = new data type [number of rows] [number of columns]

Example:

Some common operations for arrays in Java

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.