`
xinlanzero
  • 浏览: 246008 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Collections.sort list排序

    博客分类:
  • J2EE
 
阅读更多

newList是个Value对象的List,orderId是Value对象的一个属性,现在要求根据orderId把List里的记录降序排序。使用 Collections.sort方法可实现此要求,需要自己写类实现Comparator的 compare接口,这里采用的内部类的方式,当然也可使用其他方式。

Collections.sort(newList, new Comparator<PropertyValue>(){
 public int compare(Value p1, Value p2) {
     final int count1 = p1.getOrderId();
     final int count2 = p2.getOrderId();
     return (count1 < count2 ? 1 : -1);
    }
});

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics