JAVA8对象集合排序

96 阅读1分钟

class CategoryEntity {
	private String id;
	private String name;
	private int sort;
	private Date createTime;
}

public static List<CategoryEntity> listSort(List<CategoryEntity> list) {

    List<CategoryEntity> result = list.stream().sorted((o1, o2) -> {
        return (o1.getSort() == null? 0 : o1.getSort()) - (o2.getSort() == null? 0 : o2.getSort());
    }).collect(Collectors.toList());

    return result;
}