I am running a for loop over some string values and I want to update the Arraylist value (for a particular key) in the pass of the loop only but when I search how to put arraylist values for a key,I can find the solution where the value is updated after all the values of the arraylist is updated. Suppose for key sub I want to enter the string as soon as i get value val
data.put(sub,new ArrayList<String>(val));
One can't add anything to the
ArrayList
byput(...)
, but byadd()
If you want to add value one by one to the
ArrayList
you may use foreach loop:After rephrasing the original post