Java Array Basic operations (one-dimensional)

Source: Internet
Author: User

1, the Declaration of the array:

Array type array name []

2. How to represent arrays

To use the values in the array, you can use the index to implement the array, starting with 0, using the format: array name [i], such as a[1], representing the second value

In the array to use the length of the array, the function used is length, no ()

3. Initialization of arrays

A. To literally indicate the contents of an array

Array type array name [] = {value 1, value 2}

b, indicate the size of the array, initialize all array elements using the New keyword

Array type array name [] = new array type [constant value];

4. Assigning values to arrays

A. Already assigned value

b, use the array name [constant] = value; for example: a[1]=100;

5. Use of arrays

A, iterate through the array,

Use a For loop to enhance the For loop (difference: Enhanced for loop: Only the entire data can be traversed, simplifying the statement. Improve execution efficiency)

b, find the maximum value in the array, the minimum value

Example: Array int a[] = {76,54,87,23,17}, find the maximum, minimum value in the array

c, using Java within the function Array.Sort (a), for simple sorting

D. Find the specified array element

E, copy of the array, function system.arraycopy (a,b,c,d,e);

----->a: The number to copy from the target function to the array element, B: Offset, C: target array, D: offset (that is, the index from which to start copying), E: source Array

F, array padding, function Arrays.fill (b)------>a: Target array name B: The value to populate

G, compares two arrays for equality, arrays.equals (), and the return value is a Boolean type

H, array traversal, function array.aslist (a)

There are other ways to use it roughly the same as others,

Java Array Basic operations (one-dimensional)

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.