码迷,mamicode.com
首页 > 编程语言 > 详细

Java Array

时间:2016-06-30 16:28:27      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

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;

  }

}

 

Java Array

标签:

原文地址:http://www.cnblogs.com/morningdew/p/5630147.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!