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 (for classes and methods), which are explained in detail in a later section.
Common methods in Arrays:
1. Sorting
Syntax: 650) this.width=650; "src=" http://img.mukewang.com/537427720001012101670023.jpg "/>
You can use the sort () method to sort the array, as long as the array name is placed in parentheses of the sort () method to sort (in ascending order), such as 650) this.width=650; "src=" http:/ Img.mukewang.com/5374279d0001d9a706970392.jpg "/>
Operation Result:
650) this.width=650; "src=" http://img.mukewang.com/537427ec0001076602580140.jpg "/>
2. Converting an array to a string
Syntax: 650) this.width=650; "src=" http://img.mukewang.com/5374280f000191f202020022.jpg "/>
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, such as 650) this.width=650; "src=" http:/ Img.mukewang.com/537428a000010ea608880205.jpg "/>
Operation Result: 650) this.width=650; "src=" http://img.mukewang.com/5374290a0001606604870024.jpg "/>
The Arrays class also provides a number of other ways to manipulate the array here is not listed here, and friends can read more on the wiki
Code:
Import Arrays Class
Import Java.util.Arrays;
public class HelloWorld {
public static void Main (string[] args) {
Defines a string array
String[] Hobbys = {"Sports", "Game", "movie"};
Use the sort () method of the arrays class to sort the array
Arrays.sort (Hobbys);
Use the ToString () method of the arrays class to convert the array to a string and output
System.out.println (arrays.tostring (Hobbys));
}
}
Operation Result:
[Game, movie, sports]
This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547984
Java Basics---Using the arrays class to manipulate arrays in Java (32)