Actual combat of arrays tool class in Java
java. util. The arrays class can easily manipulate arrays, and all the methods it provides are static. Static methods belong to classes, not objects belonging to classes. Therefore, you can directly use the class name and method name to call. Arrays, as a tool class, can operate arrays very well. The following describes the main functions used.
1. Fill method
The fill method is mainly used to fill arrays. Let's take the simplest int type (the same as other types)
Look at the fill source code of arrays
Example code:
Java code
Fill some array source code:
Example:
Java code
2. Sort method
From the method name, we all know that it is to sort the array. It is still the same with int type and other types.
There is an entire array sort, such as
Java code
Specify the sort of array parts:
Java code
3. Equals method
Used to compare whether the element values in two arrays are equal, or to see an array of type int. Look at the source code of arrays
Example:
Java code
4. Binarysearch method
Binary search operation can be performed on the sorted array through binarysearch method. See the source code as follows
Example:
Java code
5. Copyof method
Copy the array. The array returned by the copyof () method of arrays is a new array object, so changing the element value in the returned array will not affect the original array
For example:
Java code
The above is the actual combat of Java arrays tools introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!