List<Map> 转 Map、List分组

Map<String, Long> map = list.stream().collect(Collectors.toMap(s -> (String)s.get("key"), s -> (String) s.get("value")));

Map<String, List<User>> map = list().stream().collect(Collectors.groupingBy(User::getUserId));

Map<String, User> map = list().stream().collect(Collectors.toMap(e -> e.getUserId(), Function.identity(), (oldData, newData) -> newData));
posted @ 2022-12-03 21:53  可观可乐  阅读(1427)  评论(0)    收藏  举报