lambda去重使用collectingAndThen方法
list<Object> 对象中,如果根据Object的单个属性进行过滤去重,
则: List<User> userList = users.stream() .collect(
Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(user -> user.getName()))), ArrayList::new));
如果是根据Object中的多个对象,则:
List<User> userList = users.stream() .collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(user -> user.getName()+";"+user.getId()))), ArrayList::new));
List去重两个相同的实体类对象或者相同的单个对象字段