Convert a HashMap
Collectors.counting() returns long values for each key in this method:
private static Map<Integer, Long> countDuplicates(HashSet<Card> cards) {
return cards.stream().collect(Collectors.groupingBy(Card::getRankNumber, Collectors.counting()));
}
Is there a way to cast or convert the resulting Map from Map<Integer, Long> to Map<Integer, Integer>? Direct casting gives this exception:
Type mismatch: cannot convert from Map<Integer,Integer> to Map<Integer,Long>
Note: The implementation of my class guarantees that cards has five objects in it, so there is no chance of overflow.
from Recent Questions - Stack Overflow https://ift.tt/3iQreXY
https://ift.tt/eA8V8J
Comments
Post a Comment