HashMap解决key值相同的问题

HashMap解决key值相同的问题
某些场景需要⼀个key值下⾯对应多个值,但是map的⼀个key值只对应⼀个value值,由于hashmap相同的key值,第⼆个put进去会覆盖第⼀个的值,所以为了解决这⼀问题:所以⽤list存
如下:
List<Map<String, List<RecommendationListBO>>> hashList = new ArrayList<>();
Iterator<Map.Entry<String, List<RecommendationListBO>>> iterator = Set().iterator();
Map.Entry<String, List<RecommendationListBO>> entry;
while (iterator.hasNext()) {
entry = ();
// 往newMap中放⼊新的Entry
HashMap<String, List<RecommendationListBO>> newMap = new LinkedHashMap<>();
newMap.Key().split(",")[0], Value());
hashList.add(newMap);
}
每次new⼀个新的map,add到map的list⾥⾯。思路⼤概是这样的。

本文发布于:2024-09-20 19:47:40,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/4/92357.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:需要   进去   问题   概是   场景
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议