为了账号安全,请及时绑定邮箱和手机立即绑定

将值放入内部 Map

将值放入内部 Map

梵蒂冈之花 2022-12-28 14:28:47
我有一个看起来像这样的 ConcurrentHashMap:private Map<String,Map<String,Set<PublicKey>>> instancePairs = new ConcurrentHashMap<>();以及一个应该填充此哈希图的方法。但我无法弄清楚如何将值放入地图中目前我有:instancePairs.putIfAbsent(inMemoryInstance.getUsername(), inMemoryInstance.getId() , publicKeySet);Intellij Idea 给我这个错误:
查看完整描述

1 回答

?
凤凰求蛊

TA贡献1825条经验 获得超4个赞

正如“DDovzhenko”所提到的,你需要按照以下几行做一些事情。


//Get the map containing the ID as keys, if it doesn't exist, then create one.

Map mapValuesForName = instancePairs.getOrDefault(inMemoryInstance.getUsername(), new ConcurrentHashMap<String,Set<PublicKey>>());


//Put the publicKeySet based on the Id.

mapValuesForName.putIfAbsent(inMemoryInstance.getId(), publicKeySet);


//Store the potentially changed/new value back in original map.

instancePairs.put(mapValuesForName);


查看完整回答
反对 回复 2022-12-28
  • 1 回答
  • 0 关注
  • 72 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号