I want to create a nested HashMap of:
var myHashMap = new HashMap<String, HashMap<String, int>>();
And I want to insert records into the inner HashMap, I find myself needing to instantiate the inner HashMap if the key doesn't exist:
var myHashMap = new HashMap<String, HashMap<String, int>>();
var outerStringValue = "ABC";
var innerStringValue = "XYZ";
var innerInt = 45;
if (!myHashMap.containsKey(outerStringValue) {
var innerHashMap = new HashMap<String, int>();
innerHashMap.put(innerStringValue, innerInt);
myHashMap.put(outerStringValue, innerHashMap);
} else {
myHashMap.get(outerStringValue).put(innerStringValue, innerInt);
}
Is there a better way to do this without instantiating a new innerHashMap for each unique myHashMap (the outer HashMap) key?