原文链接:
https://blog.csdn.net/DavidSoCool/article/details/82225610
// 获得小于18岁的用户对象
List<User> list = userList.stream().filter(o ->o.getAge()<18).collect(Collectors.toList());
//获得小于18岁的用户名字
List<String> list = userList.stream() .filter(o -> o.getAge()<18)
.map(User::getName).collect(Collectors.toList());
// 通过名字分组
Map<String,List<User>> map = userList.stream().collect(Collectors.groupingBy(o -> o.getName()));
// 去重
insertList = insertList.stream().collect(Collectors.toSet()).stream().collect(Collectors.toList());
// 转map
Map<Long,User> map = list.stream().filter(a->a.getId()!=null).collect(Collectors.toMap(o->o.getId(),o->o));