seawork seawork - 7 months ago 5
Java Question

Map<String, Integer> foo - how do I get the value of the integer - JAVA

I have a method:

public void updateBoard (Map<String, Integer> foo)


How do I find out the value of the Integer? I'm trying foo.get() but it just gives me the key.

Thanks!

Answer

You get all Integer values of the Map with:

foo.values();

Because a Map is a key->value construct.

With

foo.keySet();

you get all keys.

And with

foo.get("key1");

you get the appropriate value for the key key1.

Comments