java Arrays工具類實例詳解
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)
對指定組的指定范圍按數(shù)字升序進行排序。排序的范圍從索引 fromIndex(包括)一直到索引 toIndex(不包括)。(如果 fromIndex==toIndex,則排序范圍為空。)
a - 要排序的數(shù)組
fromIndex - 要排序的第一個元素的索引(包括)
toIndex - 要排序的最后一個元素的索引(不包括)
public static void sort(Object[] a) public static void sort(Object[] a,int fromIndex, int toIndex)
同上,不過數(shù)組中的所有元素都必須實現(xiàn) Comparable 接口。此外,數(shù)組中的所有元素都必須是可相互比較的(也就是說,對于數(shù)組中的任何 e1 和 e2 元素而言,e1.compareTo(e2) 不得拋出 ClassCastException)。
保證此排序是穩(wěn)定的:不會因調(diào)用 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)
根據(jù)指定比較器產(chǎn)生的順序?qū)χ付▽ο髷?shù)組進行排序。數(shù)組中的所有元素都必須是通過指定比較器可相互比較的(也就是說,對于數(shù)組中的任何 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)
使用二分搜索法來搜索指定數(shù)組的范圍,以獲得指定對象。在進行此調(diào)用之前,必須根據(jù)指定的比較器對范圍進行升序排序。如果沒有對范圍進行排序,則結(jié)果是不確定的。如果范圍包含多個等于指定對象的元素,則無法保證找到的是哪一個。
以上就是java Arrays工具類的實例詳解,關(guān)于java的文章本站還有很多,大家可以搜索參考,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
Java中ScheduledExecutorService介紹和使用案例(推薦)
ScheduledExecutorService是Java并發(fā)包中的接口,用于安排任務(wù)在給定延遲后運行或定期執(zhí)行,它繼承自ExecutorService,具有線程池特性,可復(fù)用線程,提高效率,本文主要介紹java中的ScheduledExecutorService介紹和使用案例,感興趣的朋友一起看看吧2024-10-10
SpringBoot使用CommandLineRunner接口完成資源初始化方式
這篇文章主要介紹了SpringBoot使用CommandLineRunner接口完成資源初始化方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02
springboot掃描自定義的servlet和filter代碼詳解
本文是一篇根據(jù)作者工作經(jīng)歷總結(jié)出來的關(guān)于springboot掃描自定義的servlet和filter代碼詳解的文章,小編覺得非常不錯,這里給大家分享下,和朋友們一起學(xué)習(xí),進步。2017-10-10
window?下?win10?jdk8安裝與環(huán)境變量的配置過程
這篇文章主要介紹了window?下?win10?jdk8安裝與環(huán)境變量的配置,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-08-08
詳解SpringBoot+Mybatis實現(xiàn)動態(tài)數(shù)據(jù)源切換
這篇文章主要介紹了詳解SpringBoot+Mybatis實現(xiàn)動態(tài)數(shù)據(jù)源切換,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05
springboot如何使用@ConfigurationProperties封裝配置文件
springboot如何使用@ConfigurationProperties封裝配置文件的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08
使用spring-data-redis中的Redis事務(wù)
這篇文章主要介紹了使用spring-data-redis中的Redis事務(wù),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07
SpringBoot+mybatis+Vue實現(xiàn)前后端分離項目的示例
本文主要介紹了SpringBoot+mybatis+Vue實現(xiàn)前后端分離項目的示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-12-12

