Stream_根据对象中某个字段进行去重操作
程序员文章站
2021-12-25 10:57:20
...
List<User> lists = new ArrayList<>(
Arrays.asList(
new User("zhaoliu", "女", 27, 168),
new User("xiaohong", "女", 28, 163),
new User("xiaoming", "男", 29, 178),
new User("lisi", "女", 27, 162)
)
);
List<User> disUsers = lists.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing( U -> U.getSex()))), ArrayList::new));
System.out.println("根据对象中的某个字段进行去重操作" + disUsers);
上一篇: Electron主线程和渲染进程的交互
下一篇: Shell脚本一键生成SSL证书