java中Arrays.sort()比较器的使用
日期: 2016-01-28 分类: 个人收藏 305次阅读
1、Comparator实现
import java.util.*;
class DecentComparator implements Comparator<Integer>{
public int compare(Integer o1, Integer o2) {
return o2 - o1;
}
}
2、使用时注意必须用int的封装类Integer才能比较
Integer[] a ={1,2,3,4};
Arrays.sort(a,new DecentComparator());
除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog
上一篇: Windows内核研究总结
下一篇: 大型网站架构之分布式消息队列
精华推荐