The Java.util.Arrays class makes it easy to manipulate an array, and all of the methods it provides are static.
Has the following features:
(1) Assigning a value to an array: through the fill method.
(2) sorting an array: By the sort method , in ascending order.
(3) Compare arrays: compares the values of the elements in an array by the Equals method to be exactly equal.
(4) Finding array elements: The binarysearch method can be used to perform binary lookups of sorted arrays (requires that the original array must be ordered).
Importjava.util.Arrays; Public classMain { Public Static voidMain (string[] args) {int[]arr=New int[10]; Arrays.fill (arr,5); System.out.println (arrays.tostring (arr)); int[] Nums = {6,1,5,9,3,5,7,2,3,9}; Arrays.sort (Nums); System.out.println (arrays.tostring (nums)); int[] nums1 = {6,1,5,9,3,5,7,2,3,9}; int[] Nums2 = {6,2,5,9,3,5,7,2,3,9}; int[] Nums3 = {6,1,5,9,3,5,7,2,3,9}; System.out.println (Arrays.equals (NUMS1, NUMS2)); System.out.println (Arrays.equals (NUMS1, NUMS3)); intXb=arrays.binarysearch (Nums, 5); SYSTEM.OUT.PRINTLN (XB); }}
Note that the Nums array has been sorted before the program uses binary lookup.
Java Arrays Class Learning