1、Map转List
List list = map.entrySet().stream().sorted(Comparator.comparing(e -> e.getKey())).map(e -> new Person(e.getKey(), e.getValue())).collect(Collectors.toList());
List list = map.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getValue)).map(e -> new Person(e.getKey(), e.getValue())).collect(Collectors.toList());
List list = map.entrySet().stream().sorted(Map.Entry.comparingByKey()).map(e -> new Person(e.getKey(), e.getValue())).collect(Collectors.toList());
2、List转Map
Map result1 = list.stream().collect(Collectors.toMap(Hosting::getId, Hosting::getName));
3、List转List
List employees = persons.stream()
.filter(p -> p.getLastName().equals("l1"))
.map(p -> new Employee(p.getName(), p.getLastName(), 1000))
.collect(Collectors.toList());
4、List转一个元素
User match = users.stream().filter((user) -> user.getId() == 1).findAny().get();
5、List转Set
Set disUserIds = notifications.stream().map(notify -> notify.getNotifier()).collect(Collectors.toSet());
map操作,filter操作
1、map操作,调用这个函数后,可以改变返回的类型
2、filter操作,是对这个boolean做判断,返回true判断之后的对象