Use the Arrays class to operate Arrays in Java.

Source: Internet
Author: User

Use the Arrays class to operate Arrays in Java.

The Arrays class is a tool class provided by Java in the java. util package. This class contains methods used to directly operate arrays, for example, you can directly sort and search arrays. (classes and methods are described in the following sections ~~).

Common Methods in Arrays:

1. Sorting

Syntax:Arrays. sort (array name );

You can use the sort () method to sort the array. You only need to put the array name in the brackets of the sort () method to sort the Array (in ascending order ), for example:

Running result:

2. convert an array to a string

Syntax:Arrays. toString (array name );

You can use the toString () method to convert an array into a string. This method concatenates multiple array elements in order. Multiple elements are separated by commas (,) and spaces, for example:

The running result is: 

Elements in the output array nums: [,]

The Arrays class also provides many other methods to operate Arrays.

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.