Answers for "how to add values to hashmap java"

3

java add to map

HashMap<String, String> map = new HashMap<>();
map.put("key", "value");
Posted by: Guest on January-12-2021
0

add a value to a list java in java hashmap

if (map.get(id) == null) { //gets the value for an id)
    map.put(id, new ArrayList<String>()); //no ArrayList assigned, create new ArrayList

map.get(id).add(value); //adds value to list.
Posted by: Guest on July-01-2020

Code answers related to "how to add values to hashmap java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language