title: Java Stream GroupingBy collect in custom object
body: <p>I have a Temperature Class</p>
  
  <pre><code>class Temperature {
      double minTemp;
      double maxTemp;
      String city;
      String country;
  }
  </code></pre>
  
  <p>I have another class that maintains a collection of Temperature</p>
  
  <pre><code>class Temperatures {
      List&lt;Temperature&gt; temperatures;
  }
  </code></pre>
  
  <p>I want to group the temperatures by countryName using streams.</p>
  
  <p>What I want is </p>
  
  <pre><code>public Map&lt;String, Temperatures&gt; temperaturesByCountry()
  </code></pre>
  
  <p>But I am unable to get the Temperatures as map value using stream, what I get is List of Temperature.</p>
  
  <p>My groupingBy implementation is following</p>
  
  <pre><code>Map&lt;String, List&lt;Temperature&gt;&gt; result = this.getTemperatures()
                  .stream()
                  .collect(Collectors.groupingBy(Temperature::getCountry));
  </code></pre>
  
  <p>I want to get <code>Map&lt;String, Temperatures&gt;</code> instead of <code>Map&lt;String, List&lt;Temperature&gt;&gt;</code></p>
  
  <p>How can I achieve this.?</p>