OP.
# 1 ( ), . List < > ArrayList < > , get() ( size()) O (1), List-contract.
:
, , get(int) O(1) List. , AFAIK, size() O(1) List java.util. , # 1 List. , , LinkedList, get(int) - O(N), # 1 O(N^2).
ArrayList size(), () . # 1 , ... ArrayList s.
:
, , ConcurrentModificationException s. , , javadocs , .
# 1 ( ), . , , . , , .
If the modification in case No. 1 is performed by another thread, it is difficult to synchronize properly. The main problem is that get(int)they size()are separate operations. Even if they are individually synchronized, there is nothing to stop another thread from changing the list between calls sizeand get.
In short, iterating a list that changes at the same time is complicated and should be avoided ... unless you really know what you are doing.
source
share