stream 根据对象属性去重
时间:2021-08-19 14:50:17
收藏:0
阅读:9
List<User> users = userService.listUser();
// 根据多个属性去重(也可以单个)
List<User> list = users.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(
Comparator.comparing(user-> user.getName() + ";" + user.getAge()))), ArrayList::new)
);
原文:https://www.cnblogs.com/liyanglin/p/15160259.html
评论(0)