title: Getting the sum and max from a list using stream
body: <p>Hi I have a List where the data looks like this</p>
  
  <pre><code>[{"month":"April","day":"Friday","count":5},
  
  {"month":"April","day":"Monday","count":6},
  
  {"month":"April","day":"Saturday","count":2},
  
  {"month":"April","day":"Sunday","count":1},
  
  {"month":"April","day":"Thursday","count":7},
  
  {"month":"April","day":"Tuesday","count":8},
  
  {"month":"April","day":"Wednesday","count":10},
  
  {"month":"March","day":"Friday","count":3},
  
  {"month":"March","day":"Monday","count":2},
  
  {"month":"March","day":"Saturday","count":15},
  
  {"month":"March","day":"Sunday","count":11},
  
  {"month":"March","day":"Thursday","count":4},
  
  {"month":"March","day":"Tuesday","count":20},
  
  {"month":"March","day":"Wednesday","count":7},
  
  {"month":"May","day":"Friday","count":2},
  
  {"month":"May","day":"Monday","count":0},
  
  {"month":"May","day":"Saturday","count":7},
  
  {"month":"May","day":"Sunday","count":4},
  
  {"month":"May","day":"Thursday","count":8},
  
  {"month":"May","day":"Tuesday","count":3},
  
  {"month":"May","day":"Wednesday","count":6}]
  </code></pre>
  
  <p>My object class is </p>
  
  <pre><code>String month;
  String day;
  Integer count;
  </code></pre>
  
  <p>What I want to get by using stream is sum of count grouped by month and the day with max count for that month.</p>
  
  <p>so end result will look something like</p>
  
  <p>April, Wednesday, 39
  March, Tuesday, 62
  May, Thursday , 30</p>
  
  <p>I have been trying to use stream and grouping by but no luck. Any help is appreciated. Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code> Map&lt;String, Integer&gt; totalMap = transactions.stream().collect(Collectors.groupingBy(MonthlyTransaction::getMonth, Collectors.summingInt(MonthlyTransaction::getCount)));
       Map&lt;String, String&gt; maxMap = transactions.stream().collect(Collectors.groupingBy(MonthlyTransaction::getMonth)).values().stream().toMap(Object::getDay, Collextions.max(Object::getCount);
  </code></pre>
  
  <p>obviously the maxMap method is wrong but I do not know how to write it.</p>