I have a map:
Map> dataMap;
Now i want to add new key value pairs to the map like below:
i
This can be simplified by using the ternary operator. You don't really need the if-else statement
List list = dataMap.containsKey(key) ? dataMap.get(key) : new ArrayList<>(); list.add(someNewObject); dataMap.put(key, list);