list转map
Map<String, String> map = list.stream().collect(Collectors.toMap(Student::getName, Student::getGrade));
Map<String, Student> map2 = list.parallelStream().collect(Collectors.toMap(studen->{return studen.getName();}, stude->{return stude;}));
Map<String, User> map = users.stream().collect(Collectors.toMap(User::getName, Function.identity()));
过滤: List<User> collect = userList.stream().filter(user -> 30 >= user.getAge()).collect(Collectors.toList());
转化某一个字段为集合:List<String> customerCodes = users.stream().map(User::getCustomerCode).distinct().collect(Collectors.toList());
嵌套for循环优化
Map<String, String> map =customerInfos.parallelStream().collect(Collectors.toMap(customerInfo -> {
return customerInfo.getCustomerCode();
}, customerInfo -> {
return customerInfo.getPhone();
}));
users.stream().forEach(user -> {
user.setPhone(map.get(user.getCustomerCode()));
});