2015-11-06 65 views
0

我有以下HashMap,其中键是String并且值由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密钥的值?

+0

检查(HTTP [如何更新的值,因为在Java HashMap中的关键字?]:// stackoverflow.com/questions/4157972/how-to-update-a-value-given-a-key-in-a-java-hashmap) – sam

回答

2

这应该工作:

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

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