How to add element into ArrayList in HashMap?
HashMap<String, ArrayList<Item>> Items = new HashMap<String, ArrayList<Item>>();
I know, this is an old question. But just for the sake of completeness, the lambda version.
Map<String, List<Item>> items = new HashMap<>(); items.computeIfAbsent(key, k -> new ArrayList<>()).add(item);
2.1m questions
2.1m answers
60 comments
57.0k users