Java Operations Array

Source: Internet
Author: User

Using the Arrays class to manipulate arrays in Java

The Arrays class is a tool class provided in Java, in the Java.util package. The class contains methods for manipulating arrays directly, such as sorting, searching, and so on.

Common methods in Arrays:

1. Sorting

Syntax: arrays.sort (array name);

You can use the sort () method to sort the array by placing the array name in the parentheses of the sort () method, which you can sort by in ascending order

Sequential output using: for (int i = 0;i < scores[].length;i++)

Reverse output using: for (int i = scores[].length;i > 0;i--)

2. Converting an array to a string

Syntax: arrays.tostring (array name);

You can use the ToString () method to convert an array into a string, which connects multiple array elements sequentially, separated by commas and spaces between multiple elements.

3 , fill

Assigning a value to an array: through the Fill method.

4 , equals

Compare arrays: Compares the values of elements in an array by the Equals method.

5 , BinarySearch

Binary search: Search for the range of the specified array using the binary searching method

Using the foreach Action array

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.

Grammar:

Description: The element variable name, can be any combination of greater than or equal to two letters on the line, but not a keyword, cannot be duplicated with the array name, traversing the object is the array name

Java Operations Array

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.