java项目 List对某个字段进行排序
2017-03-16 21:09
459 查看
直接上代码:
这是一个比较类
public class ComparatorNetInfoResDto implements Comparator {
@Override public int compare(Object o1, Object o2) {
NetInfoResDto netInfoResDto1 = (NetInfoResDto)o1;
NetInfoResDto netInfoResDto2 = (NetInfoResDto)o2;
int flag1 = netInfoResDto1.getNetVolume()-(netInfoResDto1.getCarCount()-Integer.parseInt(netInfoResDto1.getRentCar()));
int flag2 = netInfoResDto2.getNetVolume()-(netInfoResDto2.getCarCount()-Integer.parseInt(netInfoResDto2.getRentCar()));
if(flag1-flag2==0){
return (int) (netInfoResDto1.getNetId()-netInfoResDto2.getNetId());
}
else{
return flag1-flag2;
}
}
}
然后代码直接调用 ComparatorNetInfoResDto comparator=new ComparatorNetInfoResDto(); Collections.sort(netInfoResDtos, comparator);
这是一个比较类
public class ComparatorNetInfoResDto implements Comparator {
@Override public int compare(Object o1, Object o2) {
NetInfoResDto netInfoResDto1 = (NetInfoResDto)o1;
NetInfoResDto netInfoResDto2 = (NetInfoResDto)o2;
int flag1 = netInfoResDto1.getNetVolume()-(netInfoResDto1.getCarCount()-Integer.parseInt(netInfoResDto1.getRentCar()));
int flag2 = netInfoResDto2.getNetVolume()-(netInfoResDto2.getCarCount()-Integer.parseInt(netInfoResDto2.getRentCar()));
if(flag1-flag2==0){
return (int) (netInfoResDto1.getNetId()-netInfoResDto2.getNetId());
}
else{
return flag1-flag2;
}
}
}
然后代码直接调用 ComparatorNetInfoResDto comparator=new ComparatorNetInfoResDto(); Collections.sort(netInfoResDtos, comparator);
相关文章推荐
- java list按照 对象 指定多个字段属性进行排序
- java list按照元素对象的指定多个字段属性进行排序
- java中list里面存放map,根据map中的某一个字段进行排序 lambda
- java list按照元素对象的指定多个字段属性进行排序
- java中list里面存放map,根据map中的某一个字段进行排序
- JAVA_WEB项目之Lucene实现检索结果排序和关键字在索引库中多字段查询结果进行高亮显示
- java中list里面存放map,根据map中的某一个字段进行排序
- java对list里面的对象进行多字段排序(借鉴整理)
- java中list里面存放map,根据map中的某一个字段进行排序
- java list按照元素对象的指定多个字段属性进行排序
- List<Entity>排序:根据javabean中的一个字段对beanList进行排序
- java list按照 对象 指定多个字段属性进行排序
- java list对元素进行指定多个字段属性按多种排序方式进行排序
- java list按照 对象 指定多个字段属性进行排序
- java list按照元素对象的指定多个字段属性进行排序
- java list按照元素对象的指定多个字段属性进行排序
- Java按照List内存储的对象的某个字段进行排序的实例
- Java按照List内存储的对象的某个字段进行排序
- Java依照List内存储的对象的某个字段进行排序
- Java中对List进行排序