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

Java 中多条件排序

时间:2015-10-19 17:06:46      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

Collections.sort(ghEntityList, new Comparator<GongHuiEntity>() {
  @Override
  public int compare(GongHuiEntity o1, GongHuiEntity o2) {
  if (o1 == null || o2 == null) {
    return 0;
  }  
  //第一次比较等级
  int i = o2.getGongHuiModel().getLevel() - o1.getGongHuiModel().getLevel();
  //如果等级相同比较经验
  if(i == 0){
    int o1Exp = o1.getGongHuiModel().getExp();
    int o2Exp = o2.getGongHuiModel().getExp();
    int j = o2Exp - o1Exp;
    return j;
  }
  return i;
  }
});

Java 中多条件排序

标签:

原文地址:http://www.cnblogs.com/cci8go/p/4892272.html

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