title: java 8 get elements with equal max number of occurences
body: <p>I have a stream of elements and I want transform it to another stream that would consist only of elements that appeared the most in the previous stream assuming that I may have multiple elements with the same number of occurrences.</p>
  
  <p>As an example:</p>
  
  <p>Input stream: ['A', 'B', 'A', 'B', 'C', 'C', 'A', 'B'] </p>
  
  <p>Output stream: ['A', B'] as they both had max number of occurrences in the previous stream equal to 3.</p>
  
  <p>So far I've written the following code:</p>
  
  <pre><code>stream.collect(toMap(w -&gt; w, w -&gt; 1, Integer::sum))
                  .entrySet()
                  .stream()
                  .max(comparing(Map.Entry::getValue))
                  .map(Map.Entry::getKey);
  </code></pre>
  
  <p>But this allows me to get only one of the elements with the max number of occurrences and for the case above it would give either 'A' or 'B'.</p>
  
  <p>Is there any elegant way of how this can be achieved using lambdas?</p>
  
  <p>Thanks, Cheers</p>