This is how you can iterate over your Map
:
for (Map.Entry<String, Integer> entry : killstreaks.entrySet()) {
String key = entry.getKey();
Integer value = entry.getValue();
// continue here
}
To get a specific value (Integer
) from your Map
use:
killstreak.get("yourKey");
Seeing from your comment that you want to increment entries by 1, you can use:
killstreaks.put(key, killstreaks.get(key) + 1);
And as I see you are using Java 8 you can even use the nicer getOrDefault
:
killstreaks.put(key, killstreaks.getOrDefault(key, 0) + 1);
2
solved Java: Get hashmap value [closed]