Logic to count the number of entries corresponding to each value in a hashmap in java
<p>Currently I have sorted my Hashmap on the values field.
I need to count the number of entries associated with each value in the hashmap.</p>

<p>Initially i thought of iterating over the sorted hashmap and counting the number of entries till the value did not change. In order to get the next value, I need to get to the next entry, but there is no way to do that till one loop iteration ends.
But I was just lost in the logic and could not proceed. :(</p>

<p>I tried the other logic which uses filters in stream().
Applying the filter on the values being 1 to 50 and then counting the entries which satisfy the predicate.</p>

<pre><code>for(int i = 1; i &lt; COUNT; i++){
            int count = (int) single_count.entrySet().stream().filter(v -&gt; v.getValue() == 1).count(); //collect(Collectors.toList());
            unigram_Nc.put(i, count);
        }
</code></pre>

<p>In this case I was aware of the values in the hashmap. But I would like to know the generic solution which returns the number of entries in a hashmap corresponding to each value.
Is there any other way to count the number of entries having a particular value without knowing the values before hand ?</p>