title: Average counts from HashMap using java 8 stream API?
body: <p>I have a <code>Map</code> of the following type</p>
  
  <pre><code>public class MapUtils {
  
      private Map&lt;String, Integer&gt; queryCounts = new HashMap&lt;&gt;();
  
  public void averageCounters(){
  
      int totalCounts = queryCounts.values().stream().reduce(0, Integer::sum);
      queryCounts = queryCounts.entrySet()
                               .stream()
                               .collect(Collectors.toMap(
                                   Map.Entry::getKey,
                                   (Map.Entry::getValue)/totalCounts
      ));
  }
  </code></pre>
  
  <p>This does not compile and shows error in this line <code>(Map.Entry::getValue)/totalCounts</code>. How do I fix this? Is there a better way to get achieve average over <code>Map</code> using Java 8 API?</p>
  
  <p><strong>EDIT</strong>:
  Is this a better approach?</p>
  
  <pre><code>queryCounts.entrySet()
             .forEach(entry -&gt; queryCounts.put(entry.getKey(),
                                     entry.getValue()/totalCounts));
  </code></pre>