+ 2
I wanna find the maximum value in a hashMap<string, integer> , please how do i iterate through the hashMap?
Problem with HashMap
3 odpowiedzi
+ 6
HashMaps are not iterable, what you can do is convert the hashmap into something that you can iterate. The HashMap<String, Integer>.entrySet() returns a Set<Map.Entry<String, Integer>> that you can iterate over. A Map.Entry<String, Integer> is just a single key-value pair. To retrieve the key, use .getKey() and for the value .getValue().
+ 2
The easiest way would be to use a lambda expression
0
Something Like
integer maxV=Integer.MIN_VALUE;;
outputMap.forEach((k, v) -> {
maxV=Math.max(maxV,v);
}
one way to do it