Using the Arrays class to manipulate arrays in Java

Source: Internet
Author: User

---restore content starts---

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 (for classes and methods), which are explained in detail in a later section.

Common methods in Arrays:

Sort

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

Convert an array to a string

Syntax: arrays.tostring (array name);

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

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. To understand the meaning of foreach as "for each" from the literal meaning of English.

Grammar:

for (element type element variable: Traverse object)

Using the Arrays class to manipulate 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.