title: Generate object using Java streams
body: <p>I have a question regarding Java streams. I built below maps.</p>
  <ol>
  <li>One map includes country name as key and list of cities as value.</li>
  <li>Another includes Continent name as key and list of countries as value.</li>
  </ol>
  <pre><code>List&lt;String&gt; inCities = new ArrayList&lt;String&gt;(Arrays.asList(&quot;Delhi&quot;, &quot;Mumbai&quot;, &quot;Hyderabad&quot;, &quot;Banglore&quot;, &quot;Chennai&quot;));
  List&lt;String&gt; jpCities = new ArrayList&lt;String&gt;(Arrays.asList(&quot;Tokyo&quot;, &quot;Osaka&quot;, &quot;Kyoto&quot;));
  List&lt;String&gt; usCities = new ArrayList&lt;String&gt;(Arrays.asList(&quot;Dallas&quot;, &quot;Chicago&quot;, &quot;NewYork&quot;));
  List&lt;String&gt; ukCities = new ArrayList&lt;String&gt;(Arrays.asList(&quot;London&quot;, &quot;Cardiff&quot;, &quot;Oxford&quot;));
  List&lt;String&gt; frCities = new ArrayList&lt;String&gt;(Arrays.asList(&quot;Paris&quot;, &quot;Marseille&quot;, &quot;Lyon&quot;));
  
  Map&lt;String, List&lt;String&gt;&gt; countryWiseCities = new HashMap&lt;String, List&lt;String&gt;&gt;();
  countryWiseCities.put(&quot;India&quot;, inCities);
  countryWiseCities.put(&quot;Japan&quot;, jpCities);
  countryWiseCities.put(&quot;USA&quot;, usCities);
  countryWiseCities.put(&quot;UK&quot;, ukCities);
  countryWiseCities.put(&quot;France&quot;, frCities);
  
  List&lt;String&gt; asiaCountries = new ArrayList&lt;String&gt;(Arrays.asList(&quot;India&quot;, &quot;Japan&quot;));
  List&lt;String&gt; northAmericaCountries = new ArrayList&lt;String&gt;(Arrays.asList(&quot;USA&quot;, &quot;Canada&quot;));
  List&lt;String&gt; europeCountries = new ArrayList&lt;String&gt;(Arrays.asList(&quot;UK&quot;, &quot;France&quot;));
  Map&lt;String, List&lt;String&gt;&gt; continentWiseCountries = new HashMap&lt;String, List&lt;String&gt;&gt;();
  continentWiseCountries.put(&quot;Asia&quot;, asiaCountries);
  continentWiseCountries.put(&quot;NorthAmerica&quot;, northAmericaCountries);
  continentWiseCountries.put(&quot;Europe&quot;, europeCountries);
  </code></pre>
  <p>Existing maps.</p>
  <pre><code>{&quot;India&quot;:[&quot;Delhi&quot;, &quot;Mumbai&quot;, &quot;Hyderabad&quot;, &quot;Banglore&quot;, &quot;Chennai&quot;], &quot;Japan&quot;:[&quot;Tokyo&quot;, &quot;Osaka&quot;, &quot;Kyoto&quot;], &quot;USA&quot;:[&quot;Dallas&quot;, &quot;Chicago&quot;, &quot;NewYork&quot;], &quot;Canada&quot;:[&quot;Ontario&quot;, &quot;Toronto&quot;, &quot;vancouver&quot;],
  &quot;UK&quot;:[&quot;London&quot;, &quot;Cardiff&quot;, &quot;Oxford&quot;], &quot;France&quot;:[&quot;Paris&quot;, &quot;Marseille&quot;, &quot;Lyon&quot;]}
  
  {&quot;Asia&quot;:[&quot;India&quot;, &quot;Japan&quot;], &quot;NorthAmerica&quot;:[&quot;USA&quot;, &quot;Canada&quot;], &quot;Europe&quot;:[&quot;UK&quot;, &quot;France&quot;]}
  </code></pre>
  <p>I am looking for a way to build below map using java streams. What is the simplest way to achieve below output using Java streams?.</p>
  <p>Expected output:</p>
  <pre><code>{&quot;ASIA&quot;:[&quot;Delhi&quot;, &quot;Mumbai&quot;, &quot;Hyderabad&quot;, &quot;Banglore&quot;, &quot;Chennai&quot;, &quot;Tokyo&quot;, &quot;Osaka&quot;, &quot;Kyoto&quot;],
  &quot;NorthAmerica&quot;:[&quot;Dallas&quot;, &quot;Chicago&quot;, &quot;NewYork&quot;, &quot;Ontario&quot;, &quot;Toronto&quot;, &quot;vancouver&quot;],
  &quot;Europe&quot;:[&quot;London&quot;, &quot;Cardiff&quot;, &quot;Oxford&quot;, &quot;Paris&quot;, &quot;Marseille&quot;, &quot;Lyon&quot;]
  </code></pre>
  <ol>
  <li>Here key is continent name.</li>
  <li>Value is list cities in countries in a particular continent.</li>
  </ol>
  <p>Below is the code which I tried.</p>
  <pre><code>Map&lt;String, List&lt;Map.Entry&lt;String, List&lt;String&gt;&gt;&gt;&gt; collect1 = countryWiseCities.entrySet().stream()
                  .collect(Collectors.groupingBy(Map.Entry::getKey));
  </code></pre>