java Arrays工具类实例详解
发布于 2020-4-6|
复制链接
摘记: Arrays工具类属于java中常用的工具类
```java
public static void sort(int[] a)
public static void sort(int[] a,int fromIndex, int toIndex)
public static void sor ..
Arrays工具类属于java中常用的工具类
```java
public static void sort(int[] a)
public static void sort(int[] a,int fromIndex, int toIndex)
public static void sort(long[] a)
public static void sort(long[] a,int fromIndex, int toIndex)
public static void sort(short[] a)
public static void sort(short[] a,int fromIndex, int toIndex)
public static void sort(char[] a)
public static void sort(char[] a,int fromIndex, int toIndex)
public static void sort(byte[] a)
public static void sort(byte[] a,int fromIndex, int toIndex)
public static void sort(double[] a)
public static void sort(double[] a,int fromIndex, int toIndex)
public static void sort(float[] a)
public static void sort(float[] a,int fromIndex, int toIndex)
```
对指定组的指定范围按数字升序进行排序。排序的范围从索引 fromIndex(包括)一直到索引 toIndex(不包括)。(如果 fromIndex==toIndex,则排序范围为空。)
a - 要排序的数组
fromIndex - 要排序的第一个元素的索引(包括)
toIndex - 要排序的最后一个元素的索引(不包括)
```java
public static void sort(Object[] a)
public static void sort(Object[] a,int fromIndex, int toIndex)
```
同上,不过数组中的所有元素都必须实现 Comparable 接口。此外,数组中的所有元素都必须是可相互比较的(也就是说,对于数组中的任何 e1 和 e2 元素而言,e1.compareTo(e2) 不得抛出 ClassCastException)。
保证此排序是稳定的:不会因调用 sort 方法而对相等的元素进行重新排序。
```java
public static void sort(T[] a, Comparator c)
public static void sort(T[] a,int fromIndex,int toIndex,Comparator c)
```
根据指定比较器产生的顺序对指定对象数组进行排序。数组中的所有元素都必须是通过指定比较器可相互比较的(也就是说,对于数组中的任何 e1 和 e2 元素而言,c.compare(e1, e2) 不得抛出 ClassCastException)。
```java
public static int binarySearch(long[] a,long key)
public static int binarySearch(long[] a,int fromIndex,int toIndex,long key)
public static int binarySearch(int[] a,int key)
public static int binarySearch(int[] a,int fromIndex,int toIndex,int key)
public static int binarySearch(short[] a,short key)
public static int binarySearch(short[] a,int fromIndex,int toIndex,short key)
public static int binarySearch(char[] a,char key)
public static int binarySearch(char[] a,int fromIndex,int toIndex,char key)
public static int binarySearch(byte[] a,byte key)
public static int binarySearch(byte[] a,int fromIndex,int toIndex,byte key)
public static int binarySearch(double[] a,double key)
public static int binarySearch(double[] a,int fromIndex,int toIndex,double key)
public static int binarySearch(float[] a,float key)
public static int binarySearch(float[] a,int fromIndex,int toIndex,float key)
public static int binarySearch(Object[] a,Object key)
public static int binarySearch(Object[] a,int fromIndex,int toIndex,Object key)
public static int binarySearch(T[] a,T key,Comparator c)
public static int binarySearch(T[] a,int fromIndex,int toIndex,T key,Comparator c)
```