【问题标题】:How could I combine two hash maps of <String, Integer> to one HashMap of <HashMap<String, String>, Integer>?如何将 <String, Integer> 的两个哈希映射组合成 <HashMap<String, String>, Integer> 的一个 HashMap?
【发布时间】:2021-10-25 17:51:45
【问题描述】:

HashMap 和 HashMap 到 HashMap , Integer1+Integer2>

【问题讨论】:

  • 听起来不粗鲁,但我认为您需要复习地图构造的基本知识。因为我真的不确定你想要什么结果。
  • 你能发一个你遇到问题的例子吗

标签: java java-8


【解决方案1】:

查看 hashmap 包含 Map(Key, Value) 所以如果你想合并 hashmap 那么你正在改变键。 因此,如果您想添加多个键,则可以使用

Map&lt;Map.Entry&lt;String,String&gt;, Integer&gt; map = new HashMap&lt;&gt;();

map.put(Map.entry("onekey", "2nd Keys"), 0);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-26
    • 2016-06-11
    • 2015-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多