根据Collect集合中对象的某个属性对list排序

List<TraineeVo> l= traineeDao.getTrainees();
            Collections.sort(l,new Comparator<TraineeVo>(){
                @Override
                public int compare(TraineeVo t1,TraineeVo t2){
                    return t1.getDates().compareTo(t2.getDates());
                }
            });



public class TraineeVo {
    private String name;
    private String unit;
    private String duty;
       
    private String dates;
}    

按照TraineeVo中的date属性排序(规则自定);

Collects集合工具类中的sort方法自定义compare规则(重写compare方法);

上一篇:10.14 模拟考试


下一篇:Mybatis中xml批量执行Oracle的Sql必须加上 BEGIN END;