- forEach 函数使用
```java
List
list = JSON.parseObject(str, new TypeReference - >() {});
List
failList = new ArrayList<>(list.size());
list.forEach(taskExcuteVo -> { failList.add(taskExcuteVo.getCaseFailCount() + taskExcuteVo.getCaseLockCount()); });
通过 forEach 函数,指定 list 里面的每个变量均执行函数体里面的代码。2. `stream().map` 将一个 list 里面部分字段组装成另一个list```javaList<Integer> projectIdList = new ArrayList<>();List<Project> projects = projectService.selectProjectAll(0);projectIdList = projects.stream().map(Project::getProjectId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
steam().collect将 list 里面部分字段组装成 map/*** 生成 id -> user 的 Map*/public Map<Long, User> getUserMapByIds(List<Integer> userIds) {List<User> users = getUsersByIds(userIds);return users.stream().collect(Collectors.toMap(User::getUserId, Function.identity(), (k1, k2) -> k1));}
