对象键= 0的Collections.sort

时间:2018-11-27 11:06:33

标签: sorting collections java-7

当列表中的对象具有primaryKey = 0时,即使它是关于比较日期的,我的Collections.sort()也不起作用。为什么呢!

private void sortListByDate(List<MyObject> listMyObject) {
    Collections.sort(listMyObject, new Comparator<MyObject>() {
        @Override
        public int compare(MyObject o1, MyObject o2) {
                return o2.getTariffDate().compareTo(o1.getTariffDate());

        }
     });
    }

example of input:  
list of 3 objects:  
    First Object: key:0 , tariffDate: 27/11/2018  
    Second Object: key:0 , tariffDate: 26/11/2018  
    Third Object: key:0 , tariffDate:28/11/2018

Output expected:  
    First Object: key:0 , tariffDate: 26/11/2018  
    Second Object: key:0 , tariffDate: 27/11/2018  
    Third Object: key:0 , tariffDate:28/11/2018

不得不提的是,键为0,因为它们尚未在数据库中创建。

0 个答案:

没有答案