title: Map of maps - how to keep the inner maps as maps?
body: <p>My goal is to create a map of maps so that I can retrieve info of the outer map by its key and then access its "inner" maps by their keys.  </p>
  
  <p>However, when I got each inner map, the map I created originally became an Object and I cannot use key to access its value as I do with the outer map.</p>
  
  <p>To learn from you experts, I would like to know how to keep all the maps as maps.  Or, is it possible at all?</p>
  
  <p>here is my exercise program:</p>
  
  <pre><code>import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  
  public class MapExample {
  
      public static void main(String[] args) {
  
          Map&lt;Object,String&gt; mp=new HashMap&lt;Object, String&gt;();
  
          // adding or set elements in Map by put method key and value pair
          mp.put(new Integer(2), "Two");
          mp.put(new Integer(1), "One");
          mp.put(new Integer(3), "Three");
          mp.put(new Integer(4), "Four");
  
          Map&lt;Object,String&gt; mp2=new HashMap&lt;Object, String&gt;();
          mp2.put(new Integer(2), "Two2");
          mp2.put(new Integer(1), "One2");
          mp2.put(new Integer(3), "Three2");
          mp2.put(new Integer(4), "Four2");
  
          Map&lt;Object,String&gt; mpMaps=new HashMap();
  
          mpMaps.put("Map1",mp);
          mpMaps.put("Map2",mp2);
  
          System.out.println("This is a map of Maps:   " + mpMaps); 
  
          for (int i=0;i&lt;mpMaps.size();i++){
                       ArrayList a = new ArrayList(mpMaps.keySet());
                       Object o=a.get(i);
                       System.out.println("all together: " + mpMaps.size() + "each element is:  " + o + " value: " + mpMaps.get(o));
          }             
      }
  }
  </code></pre>
  
  <p><strong>SOLUTIONS:</strong></p>
  
  <pre><code>   Map&lt;Object,Map&lt;Object,String&gt;
      Map&lt;String, Object&gt; mpMaps=new HashMap&lt;String, Object&gt;(); 
  </code></pre>
  
  <p>by ameer and sleske</p>