Java8根据list中某个字段排序

Java8根据list中某个字段排序

排序

List list = new ArrayList<>(tempList);//tempList中有user对象
list.stream().sorted(Comparator.comparing(User::getSort)).collect(Collectors.toList());
return list;

//需要逆序
list.stream().sorted(Comparator.comparing(User::getSort).reversed()).collect(Collectors.toList());
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章