欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java Arrays工具类实例详解

程序员文章站 2023-01-07 14:18:31
arrays工具类属于java中常用的工具类 public static void sort(int[] a) public static void so...

arrays工具类属于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 - 要排序的最后一个元素的索引(不包括)

public static void sort(object[] a) 
public static void sort(object[] a,int fromindex, int toindex) 

 同上,不过数组中的所有元素都必须实现 comparable 接口。此外,数组中的所有元素都必须是可相互比较的(也就是说,对于数组中的任何 e1 和 e2 元素而言,e1.compareto(e2) 不得抛出 classcastexception)。

保证此排序是稳定的:不会因调用 sort 方法而对相等的元素进行重新排序。

public static <t> void sort(t[] a, comparator<? super t> c) 
public static <t> void sort(t[] a,int fromindex,int toindex,comparator<? super t> c) 

 根据指定比较器产生的顺序对指定对象数组进行排序。数组中的所有元素都必须是通过指定比较器可相互比较的(也就是说,对于数组中的任何 e1 和 e2 元素而言,c.compare(e1, e2) 不得抛出 classcastexception)。

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 <t> int binarysearch(t[] a,t key,comparator<? super t> c) 
public static <t> int binarysearch(t[] a,int fromindex,int toindex,t key,comparator<? super t> c) 

 使用二分搜索法来搜索指定数组的范围,以获得指定对象。在进行此调用之前,必须根据指定的比较器对范围进行升序排序。如果没有对范围进行排序,则结果是不确定的。如果范围包含多个等于指定对象的元素,则无法保证找到的是哪一个。

以上就是java arrays工具类的实例详解,关于java的文章本站还有很多,大家可以搜索参考,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!