【问题标题】:Update the value of specified key in HashMap更新HashMap中指定键的值
【发布时间】:2016-02-07 17:37:09
【问题描述】:

我有以下 HashMap,其中键是字符串,值由 HashMap 表示。

HashMap<String, HashMap<String, Integer>  outerMap = new  HashMap<String,HashMap<String, Integer>();
HashMap<String, Integer> innerMap = new HashMap<String, Integer>();
innerMap.put("Amount", 2000);
outerMap.put("TutionFee", innerMap);

现在我想更新Amount 键的值。如何更新Amount 键的值?

【问题讨论】:

标签: java hashmap


【解决方案1】:

这应该可行:

outerMap.get("TutionFee").put("Amount", newValue);

【讨论】:

    【解决方案2】:

    假设要更新的新值为1000,则outerMap.get("TutionFee").put("Amount", 1000);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-15
      • 2016-04-21
      • 2020-06-26
      • 2011-10-09
      • 2021-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多