原文链接:
https://blog.csdn.net/DavidSoCool/article/details/82225610

// 获得小于18岁的用户对象

  1. List<User> list = userList.stream().filter(o ->o.getAge()<18).collect(Collectors.toList());

//获得小于18岁的用户名字

  1. List<String> list = userList.stream() .filter(o -> o.getAge()<18)
  2. .map(User::getName).collect(Collectors.toList());

// 通过名字分组

  1. Map<String,List<User>> map = userList.stream().collect(Collectors.groupingBy(o -> o.getName()));

// 去重

  1. insertList = insertList.stream().collect(Collectors.toSet()).stream().collect(Collectors.toList());

// 转map

  1. Map<Long,User> map = list.stream().filter(a->a.getId()!=null).collect(Collectors.toMap(o->o.getId(),o->o));