HashMap value change after "get"

java

Solution

You only need to add a List if it wasn't there before. A pattern I use is

List<ProductScheme> list = discountMap.get(key);
if (list == null)
    discountMap.put(key, list = new ArrayList<>());
list.add(value);

Problem

I have a ``` private Map<String,List<ProductScheme>> discountMap = new HashMap<String,List<ProductScheme>>(); ``` now if i get list from `discountMap` and add an item in list will i have to put the list again in `discount map` or it will not be required ??

Original source

Related problems