List<User> distinctList = new ArrayList();
User user1 = new User();
user1.setId("111");
distinctList.add(user1);
User user2 = new User();
user2.setId("222");
distinctList.add(user2);
User user3 = new User();
user3.setId("333");
distinctList.add(user3);
User user4 = new User();
user4.setId("333");
distinctList.add(user4);
List<User> res = distinctList.stream().collect(//list是需要去重的list,返回值是去重后的list
Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getId()))), ArrayList::new));
System.out.println(res);