Java List对象排序

升序

Collections.sort(list, new Comparator() {
    @Override
    public int compare(T o1,
                       T o2) {
        return o1.getXxx().compareTo(o2.getXxx());
    }
});

降序

Collections.sort(list, Collections.reverseOrder(new Comparator() {
    @Override
    public int compare(T o1,
                       T o2) {
        return o1.getXxx().compareTo(o2.getXxx());
    }
}));

你可能感兴趣的:(Java List对象排序)