【Java】java8 list去重其中某个相同属性
目录
- stream流
stream流
// 去重Id相同的患者
// idRequest是请求参数
List<Research> infoList = client.getResearch(idRequest)
.getDataAs(ResearchWc.class).getInfos().stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(
Research::getId))), ArrayList::new));
// 简版 list你获取到的list
List<Research> infoList = list.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(
Research::getId))), ArrayList::new));