当值为 ArrayList 时,将键值插入 HashTable

Insert key value to HashTable when value is an ArrayList

我 运行 对一些字符串值进行 for 循环,我只想在循环的传递中更新 Arraylist 值(对于特定键),但是当我搜索如何将 arraylist 值用于一个键,我可以找到arraylist的所有值更新后更新值的解决方案。 假设对于 key sub 我想在获得值 val

后立即输入字符串
                data.put(sub,new ArrayList<String>(val));

Is there any way to add elements to the Arraylist (value) one by one rather than one time with put.

无法通过 put(...)ArrayList 添加任何内容,但通过 add()

如果您想将值一个一个地添加到 ArrayList 您可以使用 foreach 循环:

for(TypeOfTheSingleElementFromTheSet variable: setOfElementsWhichImplementsIterable){
    list.add(variable);
}

改写原文后post

data.get(sub).add(val); //where data is reference to an object which implements Map interface