2015-11-06 68 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);