笔记:Map(就是用来Ctrl+C,V的)
JDK1.8:List -> Map:
1,Map<String, String> maps = userList.stream().collect(Collectors.toMap(User::getId, User::getAge, (key1, key2) -> key2));
2,分组
Map<String, List<User>> groupBySex = userList.stream().collect(Collectors.groupingBy(User::getSex));
3,对象list 转 属性list :
List<Integer> userIds = userList.stream().map(u -> u.getId()).collect(Collectors.toList());

浙公网安备 33010602011771号