title: Counting objects with a same property value
body: <p>I'm creating a poker rank solver and I have to count cards with same suit or same rank in a set of cards. Here I create <code>HashMap</code> and increment value if multiple ranks are in the set.</p>
  
  <pre><code>private boolean isFourOfAKind() {
          Map&lt;RANK, Integer&gt; rankDuplicates = new HashMap&lt;&gt;();
          for(Card card : cards) {
              rankDuplicates.put(card.getRank(), rankDuplicates.getOrDefault(card.getRank(), 0) + 1);
          }
          return rankDuplicates.containsValue(4);
      }
  </code></pre>
  
  <p>I was wondering is it possible using streams do exact same things with java streams. It would look something like this: </p>
  
  <pre><code>    private boolean isFourOfAKind() {
          Map&lt;RANK, Integer&gt; rankDuplicates = cards.stream()
              .map(Card::getRank)
              .collect(Collectors.toMap(/*...something goes here..*/)); // of course this is very wrong, but you can see what I'm aiming at.
          return rankDuplicates.containsValue(4);
      }
  </code></pre>