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.
Common methods in Arrays:
1. Sorting
Syntax: arrays.sort (array name);
You can use the sort () method to sort the array by placing the array name in the parentheses of the sort () method, which you can sort by in ascending order
Sequential output using: for (int i = 0;i < scores[].length;i++)
Reverse output using: for (int i = scores[].length;i > 0;i--)
2. Converting an array to a string
Syntax: arrays.tostring (array name);
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.
3 , fill
Assigning a value to an array: through the Fill method.
4 , equals
Compare arrays: Compares the values of elements in an array by the Equals method.
5 , BinarySearch
Binary search: Search for the range of the specified array using the binary searching method
Using the foreach Action array
foreach is not a keyword in Java, it is a special simplified version of A for statement, which is simpler and easier to iterate through arrays and collections.
Grammar:
Description: The element variable name, can be any combination of greater than or equal to two letters on the line, but not a keyword, cannot be duplicated with the array name, traversing the object is the array name
Java Operations Array