java Arrays工具类实例详解

 更新时间:2017年07月19日 10:22:50   作者:神绮_H_亚里亚  
这篇文章主要介绍了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) 
 

 对指定组的指定范围按数字升序进行排序。排序的范围从索引 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的文章本站还有很多,大家可以搜索参考,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

相关文章

  • Java中ScheduledExecutorService介绍和使用案例(推荐)

    Java中ScheduledExecutorService介绍和使用案例(推荐)

    ScheduledExecutorService是Java并发包中的接口,用于安排任务在给定延迟后运行或定期执行,它继承自ExecutorService,具有线程池特性,可复用线程,提高效率,本文主要介绍java中的ScheduledExecutorService介绍和使用案例,感兴趣的朋友一起看看吧
    2024-10-10
  • SpringBoot使用CommandLineRunner接口完成资源初始化方式

    SpringBoot使用CommandLineRunner接口完成资源初始化方式

    这篇文章主要介绍了SpringBoot使用CommandLineRunner接口完成资源初始化方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-02-02
  • springboot扫描自定义的servlet和filter代码详解

    springboot扫描自定义的servlet和filter代码详解

    本文是一篇根据作者工作经历总结出来的关于springboot扫描自定义的servlet和filter代码详解的文章,小编觉得非常不错,这里给大家分享下,和朋友们一起学习,进步。
    2017-10-10
  • window 下 win10 jdk8安装与环境变量的配置过程

    window 下 win10 jdk8安装与环境变量的配置过程

    这篇文章主要介绍了window 下 win10 jdk8安装与环境变量的配置,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-08-08
  • 详解springMVC容器加载源码分析

    详解springMVC容器加载源码分析

    这篇文章主要介绍了详解springMVC容器加载源码分析,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05
  • VsCode搭建Java开发环境的方法

    VsCode搭建Java开发环境的方法

    这篇文章主要介绍了VsCode搭建Java开发环境的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-11-11
  • 详解SpringBoot+Mybatis实现动态数据源切换

    详解SpringBoot+Mybatis实现动态数据源切换

    这篇文章主要介绍了详解SpringBoot+Mybatis实现动态数据源切换,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-05-05
  • springboot如何使用@ConfigurationProperties封装配置文件

    springboot如何使用@ConfigurationProperties封装配置文件

    springboot如何使用@ConfigurationProperties封装配置文件的操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-08-08
  • 使用spring-data-redis中的Redis事务

    使用spring-data-redis中的Redis事务

    这篇文章主要介绍了使用spring-data-redis中的Redis事务,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-07-07
  • SpringBoot+mybatis+Vue实现前后端分离项目的示例

    SpringBoot+mybatis+Vue实现前后端分离项目的示例

    本文主要介绍了SpringBoot+mybatis+Vue实现前后端分离项目的示例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-12-12

最新评论