美文网首页
List转Map

List转Map

作者: 抄无止境 | 来源:发表于2020-06-08 09:27 被阅读0次

参考
List转Map的三种方法

第一种 Map<Long, User>
Map<Long, User> maps = userList.stream().collect(Collectors.toMap(User::getId, Function.identity(), (key1, key2) -> key2));
第二种
Map<Long, String> maps = userList.stream().collect(Collectors.toMap(User::getId, User::getAge, (key1, key2) -> key2));

相关文章

网友评论

      本文标题:List转Map

      本文链接:https://www.haomeiwen.com/subject/aszazhtx.html