Okay so I have spent several hours trying to wrap my head around this concept of a HashMap in Java but am just not able to figure it out. I have looked at many tutorials but
HashMap> myArray = new HashMap>();
if (!myArray.containsKey("en")) {
myArray.put("en", new HashMap());
}
myArray.get("en").put("name", "english name");
In Java you have to be explicit about when you are creating an object. In this case first we check if there is already a HashMap
object stored in our outer HashMap
under the key "en". If not, we create an empty one.
Now to put a new value into it we have to first get it from the outer HashMap
, then put the new value.