Collections.sort 的日期排序

    public static void main(String[] args) throws ParseException {    //  sort降序排列
        List dates = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date dd = sdf.parse("2000-11-11 12:12:21");
        Date aa = sdf.parse("2002-11-11 12:12:21");
        Date date = new Date();


        dates.add(date);
        dates.add(dd);
        dates.add(aa);
        Collections.sort(dates, new Comparator() {

            @Override
            public int compare(Date o1, Date o2) {
                int flag = o2.compareTo(o1);
                return flag;
            }
        });

        System.out.println(dates.get(0));
    }

 

转载于:https://www.cnblogs.com/cuixiaomeng/p/10233638.html

你可能感兴趣的:(Collections.sort 的日期排序)