title: Java HashMap associative multi dimensional array can not create or add elements
body: <p>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 none seem to address my exact requirement and I cannot get it to work.</p>
  
  <p>I am trying to create an associative multi dimensional array in Java (or something similar) so that I can both save to and retrieve from the array with keys that are Strings.</p>
  
  <p>This is how I would do it in PHP and explains it best what I am trying to do:</p>
  
  <pre><code>//loop one - assign the names
  myArray['en']['name'] = "english name";
  myArray['fr']['name'] = "french name";
  myArray['es']['name'] = "spanish name";
  
  //loop two - assign the description
  myArray['en']['desc'] = "english description";
  myArray['fr']['desc'] = "french description";
  myArray['es']['desc'] = "spanish description";
  
  //loop three - assign the keywords
  myArray['en']['keys'] = "english keywords";
  myArray['fr']['keys'] = "french keywords";
  myArray['es']['keys'] = "spanish keywords";
  
  //later on in the code be able to retrive any value similar to this
  english_name = myArray['en']['name'];
  french_name = myArray['fr']['name'];
  spanish_name = myArray['es']['name'];
  </code></pre>
  
  <p>This is what I tried in Java but it is not working:</p>
  
  <pre><code>HashMap&lt;String, HashMap&lt;String, String&gt;&gt; myArray = new HashMap&lt;String, HashMap&lt;String, String&gt;&gt;();
  
  myArray.put("en" , put("name", "english name")); //gives me "cannot find symbol" at second put
  
  myArray.put("en" , ("name", "english name")); //gives me "')' expected" after second comma
  </code></pre>
  
  <p>So I am sure its something simple that I am missing but please point it out because this is very frustrating!</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>So here is some working code on how I implemented the answer I accepted:</p>
  
  <pre><code>import java.util.*;
  
  HashMap&lt;String, HashMap&lt;String, String&gt;&gt; finalArray = new HashMap&lt;String, HashMap&lt;String, String&gt;&gt;();
  
  String[] langArray = {"en","fr","de","no","es"};
  
  //Initialize each language key ahead of time
  for(String lang : langArray) { // foreach lang in langArray
    if (!finalArray.containsKey(lang)) {
      finalArray.put(lang, new HashMap&lt;String, String&gt;());
    }
  }
  
  //loop one - assign names
  for(String lang : langArray) {
    String theName = lang + " name"; //go get the name from somewhere
    finalArray.get(lang).put("name", theName);
  }
  
  //loop two - assign description
  for(String lang : langArray) {
    String theDesc = lang + " description"; //go get the description from somewhere
    finalArray.get(lang).put("desc", theDesc);
  }
  
  //loop three - assign keywords
  for(String lang : langArray) {
    String theKeys = lang + " keywords"; //go get the keywords from somewhere
    finalArray.get(lang).put("keys", theKeys);
  }
  
  //display output
  for(String lang : langArray) {
    System.out.println("LANGUAGE: " + lang);
    System.out.println(finalArray.get(lang).get("name"));
    System.out.println(finalArray.get(lang).get("desc"));
    System.out.println(finalArray.get(lang).get("keys"));
  }
  
  //example to retrieve/get values
  String english_name = finalArray.get("en").get("name");
  String french_desc = finalArray.get("fr").get("desc");
  </code></pre>