LinkedHashMap<Integer, ArrayList> LHM = new LinkedHashMap<Integer, ArrayList>(); How to add elements to ArrayList ?
LHM.put(1, new ArrayList().add("1")); LinkedHashMap<Integer, ArrayList> LHM = new LinkedHashMap<Integer, ArrayList>(); How to add elements to ArrayList ?
LHM.put(1, new ArrayList().add("1")); You can add an item as follows.
Map<Integer, List<String>> lhm = new LinkedHashMap<>(); List<String> list = lhm.getOrDefault(1, new ArrayList<>()); list.add("1"); lhm.put(1, list); You can do this:
Map<String, List<String>> map = new LinkedHashMap<>(); map .computeIfAbsent(key, k -> new ArrayList<>()) .add("value"); This option allows you to create an object only if it is really required.
Source: https://ru.stackoverflow.com/questions/678521/
All Articles