vsnyc vsnyc - 1 year ago 115
Java Question

Initial capacity for CopyOnWriteArrayList

Many List implementations have an option to specify an initial capacity for the collection, why is this not allowed for CopyOnWriteArrayList?

Answer Source

In a conventional ArrayList the capacity is a hint to reserve more space in the backing array for more elements to be added to the list later on.

In a CopyOnWriteArrayList, every (atomic) write operation creates a new backing array. There no point in preallocating an array that is bigger than the current list size because that space would never be used.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download