瞧瞧,java Stream的常用方式
list转map
List<User> userList=new ArrayList();
//Function.identity()表示自己本身
//(key1, key2) -> key2 表示key一样取后一个
Map<Long, User> maps = userList.stream().collect(Collectors.toMap(User::getId, Function.identity(), (key1, key2) -> key2));.
原创
2022-09-20 11:00:00 ·
140 阅读 ·
0 评论