zoukankan      html  css  js  c++  java
  • 数组排序 ---- Arrays.sort()方法

    Arrays.sort() 能够对对数组进行排序。

    默认从小到大排序,如需调整顺序,需要通过实现Comparator接口并调用

    Arrays.sort()可以对int[]、double[]、char[]、long[]、byte[]、short[]之类的数据类型进行排序,下面以最常见的int[]数组为例说明。

    Arrays.sort(int[] values)

    这种方式能够对int[] 、double[]、long[]之类的基本类型的数组元素进行排序,默认从小到大排序

     

    Arrays.sort(int[] a, int fromIndex, int toIndex)

    这个函数对基本类型数组从 fromIndex 到 toIndex-1 这些数据进行排序,如下所示。

     

    Arrays.sort(Object[] oj1,new SortComparator())

    这种方式能够对引用类型数组,按照Comparator中声明的compare方法对对象数组进行排序

     

    Arrays.sort(Object[] oj1 , int fromIndex , int toIndex , new SortComparator)

     

  • 相关阅读:
    Can you feel my word?
    木语录
    走在风雨中
    我看平淡生活……
    Can you feel my word?
    我看平淡生活……
    留言本
    Python(七)之匿名函数lambda
    python之常用模块logging
    python(六)之面向对象
  • 原文地址:https://www.cnblogs.com/maxiaoshuai/p/5401829.html
Copyright © 2011-2022 走看看