How do I update the element at a certain position in an ArrayList?

Saravanan picture Saravanan · Dec 4, 2010 · Viewed 234.1k times · Source

I have one ArrayList of 10 Strings. How do I update the index 5 with another String value?

Answer

HaskellElephant picture HaskellElephant · Dec 4, 2010

Let arrList be the ArrayList and newValue the new String, then just do:

arrList.set(5, newValue);

This can be found in the java api reference here.