title: Flattening a nested Hashmap using Stream
body: <p>I have a nested <code>HashMap&lt;String,Object&gt;</code> and I want to create a <code>HashMap&lt;String,String&gt;</code> by flattening the Hashmap. I have tried the solution from <a href="https://stackoverflow.com/questions/37462264/recursively-flatten-values-of-nested-maps-in-java-8">Recursively Flatten values of nested maps in Java 8</a>. But I am unable to use the class <code>FlatMap</code> as mentioned in the answer. </p>
  
  <p>I have also tried the solution in the question itself, still I am missing something. Then I found a similar use case and came up with the following solution. But it seems like I am missing something as a parameter for the lambda function <code>flatMap</code> . </p>
  
  <pre><code>public static void main(String[] args) {
    Map&lt;String,Object&gt; stringObjectMap= new HashMap&lt;String,Object&gt;();
    stringObjectMap.put("key1","value1");
    stringObjectMap.put("key2","value2");
    Map&lt;String,Object&gt; innerStringObjectMap = new HashMap&lt;&gt;();
    innerStringObjectMap.put("i1key3","value3");
    innerStringObjectMap.put("i1key4","value4");
    innerStringObjectMap.put("i1key5","value5");
    stringObjectMap.put("map1",innerStringObjectMap);
    Map&lt;String,Object&gt; innerStringObjectMap2 = new HashMap&lt;&gt;();
    innerStringObjectMap.put("i2key6","value6");
    innerStringObjectMap2.put("i2key7","value7");
    innerStringObjectMap.put("i1map2",innerStringObjectMap2);
  
    Map&lt;String,Object&gt; collect =
          stringObjectMap.entrySet().stream()
                  .map(x -&gt; x.getValue())
                  .flatMap(x -&gt; x) //I aint sure what should be give here
                  .distinct(); //there was a collect as List which i removed.
  
    //collect.forEach(x -&gt; System.out.println(x));
  
  }
  </code></pre>
  
  <p>What is a better solution for flattening a nested map? I am not just interested in the values, but also the keys in the map. That is the reason why I decided to flatten the map to get another map (I am not sure if this is even possible)</p>
  
  <p><strong>EDIT - Expected Output</strong></p>
  
  <pre><code>key1 - value1
  key2-value2
  map1 =""  //this is something i will get later for my purpose
  i1key3=value3
  .
  .
  i1map2=""
  .
  .
  i2key7=value7
  </code></pre>