I have a map of < string, List< String type>>,
What I am trying to do is add a string to map value if list is present, else create a list and add it to the list and insert in map
.
s1
, s2
are strings.
Code:
Map<String, List<String>> map = new HashMap<>();
map.put(s1,(map.getOrDefault(s1, new LinkedList<String>())).add(s2));
Error:
error: incompatible types: boolean cannot be converted to List<String>
What's wrong with this !!!