1.获取实体类对象中某一个字段转为List
List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
2.根据单个字段字段去除重复
List<User> userList = users.stream() .collect( Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(user ->user.getName()))), ArrayList::new));
3.根据多个字段去除重复
List<User> userList = users.stream() .collect( Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(user -> user.getName()+";"+user.getId()))), ArrayList::new));
4.根据某个字段分组
users.stream().collect(Collectors.groupingBy(User::getName))