Add value to list inside map <String, List> in Java 8
1 answer
You must use the Map::computeIfAbsent
to create or retrieve a List
:
myMap.computeIfAbsent(MY_KEY, k -> new ArrayList<>()).add(value);
+15
You must use the Map::computeIfAbsent
to create or retrieve a List
:
myMap.computeIfAbsent(MY_KEY, k -> new ArrayList<>()).add(value);