title: Java 8 stream "Cannot use this in a static context"
body: <p>I am new to java8 stream &amp; sorry about the stupid question .  Here is my code which i am trying to create a map of id &amp; value, but i am getting this error, not able to fix. Can anyone help me what is the alternative?</p>
  
  <pre><code>    public static Map&lt;Integer, String&gt; findIdMaxValue(){
          Map&lt;Integer, Map&lt;String, Integer&gt;&gt; attrIdAttrValueCountMap = new HashMap&lt;&gt;();
          Map&lt;Integer, String&gt; attrIdMaxValueMap = new HashMap&lt;&gt;(); 
                  attrIdAttrValueCountMap.forEach((attrId, attrValueCountMap) -&gt; {
                      attrValueCountMap.entrySet().stream().sorted(this::compareAttrValueCountEntry).findFirst().ifPresent(e -&gt; {
                          attrIdMaxValueMap.put(attrId, e.getKey());
                      });
                  });
      }
  </code></pre>
  
  <p>and sorting method</p>
  
  <pre><code>public static int compareAttrValueCountEntry(Map.Entry&lt;String, Integer&gt; e1, Map.Entry&lt;String, Integer&gt; e2) {
      int diff = e1.getValue() - e2.getValue();
      if (diff != 0) {
          return -diff;
      }
      return e1.getKey().compareTo(e2.getKey());
  }
  </code></pre>
  
  <p>I am getting this error</p>
  
  <pre><code>"Cannot use this in a static context"
  </code></pre>