Java starts from scratch (a common method of the Arrays class for arrays), and Arrays starts from scratch
I. Common Arrays Methods
Ii. Simple Example
Package com. pb. demo1; import java. util. arrays;/** several common methods in the Arrays tool class * 1. copyof * 2. toString * 3. equals * 4. sort * 5. fill * 6. binarySearch */public class ArraysTest {public static void main (String [] args) {String [] arry1 = {"Beijing", "Shanghai", "Chongqing ", "Shenzhen"}; String [] arry2 = Arrays. copyOf (arry1, 4); // copy copyof System. out. println ("arry2 is:" + Arrays. toString (arry2); // compare equals System. out. println ("is arry1 equal to arry2?" + Arrays. equals (arry1, arry2); // sort arry1 to sort Arrays. sort (arry1); // toString System. out. println ("value of arry1 after sorting:" + Arrays. toString (arry1); // after sorting, whether arry1 and arry2 are equal to equals System. out. println ("whether arry1 and arry2 are equal after sorting" + Arrays. equals (arry1, arry2); // fill in fill Arrays. fill (arry2, "Guangzhou"); System. out. println ("the value of arry2 after filling:" + Arrays. toString (arry2); // you can use System to query binarySearch only after the array has been sorted. out. println ("Location of Chongqing in arry1:" + Arrays. binarySearch (arry1, "Chongqing "));}}
Result:
Arry2 is: [Beijing, Shanghai, Chongqing, Shenzhen]
Whether arry1 and arry2 are equal: true
Value of arry1 after sorting: [Shanghai, Beijing, Shenzhen, Chongqing]
Whether arry1 and arry2 are equal after sorting is false
Value of arry2 after filling: [Guangzhou, Guangzhou]
Location of Chongqing in arry1: 3