title: How to filter map of map using java stream
body: <p>How can I filter map of map using java stream. I can do it using double loop but I think this is not efficient. </p>
  
  <pre><code>public class MapUsage {
      static Map&lt;Integer, Map&lt;Integer, String&gt;&gt; parentMap = new HashMap&lt;&gt;();
      static Map&lt;String, String&gt; userRole = new HashMap&lt;&gt;();
  
      public static void main(String ... args){
          initializeData();
          displayMapForUser("user1", parentMap);
  //        printMap(parentMap);
  
      }
  
  
      private static void displayMapForUser(String user1, Map&lt;Integer, Map&lt;Integer, String&gt;&gt; parentMap) {
          Integer role = new Integer(userRole.get(user1));
          Map&lt;Integer, Map&lt;Integer, String&gt;&gt; userMap = new HashMap&lt;&gt;();
          Map&lt;Integer, String&gt; childMap = new HashMap&lt;&gt;();
          for(Map.Entry&lt;Integer, Map&lt;Integer, String &gt;&gt; entry : parentMap.entrySet()){
              for(Map.Entry&lt;Integer, String &gt; entry1: entry.getValue().entrySet()){
                  if(entry1.getKey().equals(role))
                      childMap.put(entry1.getKey(), entry1.getValue());
              }
              userMap.put(entry.getKey(), childMap);
          }
          printMap(userMap);
      }
  
      private static void printMap(Map&lt;Integer, Map&lt;Integer, String&gt;&gt; parentMap) {
          for(Map.Entry&lt;Integer, Map&lt;Integer,String&gt; &gt; entry: parentMap.entrySet()){
              System.out.println("key: "+entry.getKey());
              System.out.println("value: "+entry.getValue());
          }
      }
  
      private static void initializeData() {
          Map&lt;Integer, String &gt; childMap1 = new HashMap&lt;&gt;();
          Map&lt;Integer, String &gt; childMap2 = new HashMap&lt;&gt;();
          userRole.put("user1", "1");
          userRole.put("user2", "2");
          userRole.put("user3", "3");
          userRole.put("user4", "4");
  
          childMap1.put(1, "one");
          childMap1.put(2, "two");
          childMap1.put(3, "three");
          childMap1.put(4, "four");
          parentMap.put(1, childMap1);
  
          childMap2.put(1, "one");
          childMap2.put(2, "two");
          childMap2.put(3, "three");
          parentMap.put(2, childMap2);
      }
  }
  </code></pre>
  
  <p>Output is: </p>
  
  <pre><code>key: 1
  value: {1=one}
  key: 2
  value: {1=one}
  </code></pre>