Java List通过时间排序

Java List通过时间排序

    /**
     * 根据时间倒叙
     *
     * @param list
     */
    private static void ListSort(List<entity> list) {
        list.sort(new Comparator<entity>() {
            @Override
            public int compare(entity e1, entity e2) {
                try {
                    if (e1.getDateTime().isAfter(e2.getDateTime())) {
                        return -1;
                    } else {
                        return 1;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return 0;
            }
        });
    }

版权声明:本文为qq_34318092原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。