根据list中属性去重
sourceProjectDataList.removeIf(sourceProject -> existProject.stream().anyMatch(project -> project.getXmid().equals(sourceProject.getXmid())));
根据list中的属性生成新的list
List<Long> xmidList = sourceProjectDataList.stream().map(SourceProjectData::getXmid).collect(Collectors.toList());
根据属性生成map
属性作为key和value
Map<String, String> collect = sourceProjectDataList.stream().collect(Collectors.toMap(SourceProjectData::getXmlxr, SourceProjectData::getDwmc));
当key相同的时候选后面的作为key
Map<Long, String> collect = sourceProjectDataList.stream().collect(Collectors.toMap(SourceProjectData::getXmid, SourceProjectData::getDwmc, (xmid1, xmid2) -> xmid2));
当key相同的时候将两个key拼接起来
Map<String, String> collect = sourceProjectDataList.stream().collect(Collectors.toMap(SourceProjectData::getFgldXm, SourceProjectData::getDwmc, (nt1, nt2) -> nt1 + "," + nt2));
属性作为key,实体作为value
Map<Long, SourceProjectData> collect = sourceProjectDataList.stream().collect(Collectors.toMap(source -> source.getXmid(), Function.identity()));
根据某个属性排序
reversed()表示倒序
List<Content> collect = contents.stream().sorted(Comparator.comparing(Content::getValue).reversed()).collect(Collectors.toList());