一,将一个List中的某个属性转成一个新的List
例子:
List<QueryOrgsResp> orgs = sysOrgMapper.queryOrgsPaging(map);
List<String> orgIds=orgs.stream().map(QueryOrgsResp::getOrgId)
.collect(Collectors.toList());
还可以用Set集合,例如:
Set<String> orgIds = orgs.stream().map(QueryOrgsResp::getOrgId)
.collect(Collectors.toSet());
二,多个属性在某个List集合中进行过滤
List<SysOrg> sysOrgs = new LambdaQueryChainWrapper<>(sysOrgMapper)
.list(); List checkStudents = students.stream()
.filter(SchoolStudent -> SchoolStudent.getStudentName().equals(schoolStudent.getStudentName()))
.filter(SchoolStudent -> !SchoolStudent.getStudentId().equals(schoolStudent.getStudentId()))
.filter(SchoolStudent -> SchoolStudent.getSchoolId().equals(schoolStudent.getSchoolId()))
.collect(Collectors.toList());
三,把一个List通过一个属性分组形成Map<id,List>
List<SubjectRes> subjectDatas = new ArrayList<>();
Map<String, List<SubjectRes>> gradeMap = subjectDatas.stream().collect(Collectors.groupingBy(SubjectRes