对一个list按userId去重
List<String> userIdList = userIdList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getUserId()))), ArrayList::new));
将一个list按userId为key,value为list<A>转成一个map
Map<String, List<A>> partsMap = resultList.stream().collect(Collectors.toMap(A::getUserId, A ->
Lists.newArrayList(A), (List<A> newValueList, List<A> oldValueList) ->
{
oldValueList.addAll(newValueList);
return oldValueList;
}));
将一个list按照年龄大小做去重处理
List<Student> distinctList = studentList.stream() .collect(Collectors.toMap(Student::getId, student -> student, (s1, s2) -> Integer.parseInt(s1.getAge()) < Integer.parseInt(s2.getAge()) ? s1 : s2)) .values() .stream() .collect(Collectors.toList());