The sorting problem is described earlier (see blog http://blog.csdn.net/qq_32059827/article/details/51362390); two-point lookup problems (see blog Http://blog.csdn.net/qq_ 32059827/article/details/51363949)
Next, a class is used to quickly implement sorting and two-point lookups. Arrays class
Import java.util.arrays;/* * Arrays: A tool class that operates on an array. such as sorting and finding. * 1:public static string toString (int[] a) returns a string representation of the contents of the specified array. * 2:public static void sort (int[] a) sorts the array, sorting the specified type of int in ascending order of numbers. * 3:public static int binarysearch (int[] a,int key) binary lookup. Use the binary search method to search for the specified array of type int to get the specified value. * A-the array to search for key-the value to search for */public class Arraysdemo {public static void main (string[] args) {//define an array int[] arr = {24, };//public static string toString (int[] a) convert the array to a string System.out.println ("before sorting:" + arrays.tostring (arr));//P ublic static void sort (int[] a) sorts the array arrays.sort (arr);//The return value is a void type, sorted before output System.out.println ("After sorting:" + Arrays.tostring (arr));//[13, 24, 57, 69, 80]. Arr = {$, S, S, Min, 80}int type array//public static int BinarySearch (int[] a,int key) binary Find//NOTE: Binary lookup of an unordered expedited group index is an incorrect idea. System.out.println ("BinarySearch:" + arrays.binarysearch (arr, 57)); System.out.println ("BinarySearch:" + arrays.binarysearch (arr, 558));}}
Visible sorting and binary lookups have become so simple.
The first season of Java arrays class