I have an ArrayList with some entries as a value in a HashMap, how to add new values to it?
Thanks.Did it like this:
Map<String, ArrayList<String>> index = new HashMap<String, ArrayList<String>>();
void add(String kword, String... urls){
if(index.containsKey(kword)){
index.get(kword).addAll(Arrays.asList(urls));
} else {
index.put(kword, (ArrayList<String>) Arrays.asList(urls));
}
}
Assuming that you have something along these lines:
then this should allow you to add new values to any list that is contained as a value in the map:
Naturally, you can also store the result of
map.get(listKey)to a temporary variable to avoid the cost ofmap.get()when inserting multiple values: