Search code examples
javaarraylistconcurrentmodification

Does editing an item in an arraylist count as modifying the list?


In an ArrayList, if I add/remove items, then this is considered 'modifying' the list. Hence, if i try to iterate over the list while simultaneously trying to add/remove items, i get ConcurrentModificationException (unless i use a listIterator).

My question is, if I do an operation like : list.get(index).setValue("newValue"), is it still considered modifying the list?


Solution

  • No. Editing an item in a List is not "modifying the List": The item is modified, not the List. The List will be unaware of any changes to the items.

    Only changes to the item references held by the List is a modification to the List, ie insertions and selections to/from the List.