Java Array

Array.sort()

 

1. Arrays.sort(int[] a):  从大到小的排序

2. Arrays.sort(int[] a, int fromIndex, int toIndex):  从大到小的排序

3. public static<T> void sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)

example for the last method:

Integer[] a = {9,8,7,2,3,4,1,0,6,5};

Comparator cmp = new MyComparator();

Arrays.sort(a, cmp);

Class MyComparator implements Comparator<Integer>{

  @Override

  public int compare(Integer o1, Integer o2){

    if(o1 < o2) return 1;

    else if (o1 > o2) return -1;

    else return 0;

  }

}

 

posted @ 2016-06-30 15:31  morningdew  阅读(207)  评论(0编辑  收藏  举报