JAVA使用stream流对对象集合根据某个字段去重
userList = userList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<>(Comparator.comparing(User::getCity))), ArrayList::new));
User::getCity 对象要去重的这段,这里表示根据城市属性进行去重
-----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------
(蓝奏云官网如果有地址失效了,可以私信我,后续看到会补充)

浙公网安备 33010602011771号