I have a HashMap
myMap = new HashMap<String, ArrayList<String> >();
I am writing a code where I want to add items in ArrayList for the key if it exists in the map,
myMap.get(key).add(element);
or else create a new ArrayList, add an item to the list, and add this list to the map.
ArrayList<String> tmpArrList = new ArrayList<>();
tmpArrList.add(element);
myMap.put(key, tmpArrayList);
Writing three lines for adding single element, do not look good to me, how can I write it in single line using Java 5.. ?