I am trying to retrieve all the keys having maximum values in a hashmap. I have the following code that does it,
List<List<Long>> maxList = map.entrySet()
.stream()
.filter(entry -> entry.getValue() == maxCount)
.map(Map.Entry::getKey)
.collect(Collectors.toList());
And my map has multiple entries having the same value. But it is fetching only the last entry in the map. Any idea on why this is happening? Any help greatly appreciated!