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.