JAVA LIST按照指定字段去重重复
JAVA List按照指定字段去重重复
List<TalentPlanStudentEntity> studentList = relatePlanStudentList.stream() .collect(Collectors.collectingAndThen(Collectors.toCollection( () -> new TreeSet<>(Comparator.comparing(TalentPlanStudentEntity::getUserId))), ArrayList::new)); List<TalentPlanStudentEntity> studentList = new ArrayList<>(relatePlanStudentList.stream() .collect(Collectors.toMap(TalentPlanStudentEntity::getUserId, Function.identity(), (oldValue, newValue) -> oldValue)) .values());
TreeMap<String, List<SdsTest>> treeMap = list.stream().collect(Collectors.groupingBy(SdsTest::getKey, TreeMap::new, Collectors.toList()));