How can I create a concurrent List instance, where I can access elements by index? Does the JDK have any classes or factory methods I can use?
CopyOnWriteArrayList
There is a concurrent List
implementation in java.util.concurrent
: CopyOnWriteArrayList
.
Caveat: CopyOnWriteArrayList
copies the entire list for each and every "mutative operations (add
, set
, and so on)". So this class performs better for read-heavy applications.