list集合中对象某个字段取出并用逗号拼接
String emailStr = userList.stream().map(User::getUserName).collect(Collectors.joining(","));
取出userName字段并转成list
List<String> collect1 = userList.stream().map(p -> p.getUserName()).collect(Collectors.toList());
List<String> collect2 = userList.stream().map(User::getUserName).collect(Collectors.toList());
将list集合中每个对象的两个字段对应取出,转成key-value格式
Map<String, Integer> nameEmailMap = userList.stream().collect(Collectors.toMap(User::getUserName, User::getId, (key1, key2) -> key2));
剔除userName等于“人间啊"的对象
List<User> result = userList.stream().filter(e -> !StringUtils.equals(e.getUserName(), "人间啊")).collect(Collectors.toList());
按照某个字段倒序排序
// 按照ID降序排列
userList.sort(Comparator.comparing(User::getId).reversed());
// 按照ID升序排列
userList.sort(Comparator.comparing(User::getId));