ConcurrentModificationException thrown by sublist [duplicate]

The subList is simple a view of the original list (see here). You are allowed to mutate elements within it but not change the structure of the list.

According to the documentation, subList behaviour is undefined if you try to make structural changes. I guess in this particular implementation, ConcurrentModificationException was decided as the undefined behaviour.

The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)

Leave a Comment