[concurrency-interest] Questions about ArrayDeque

Joshua Bloch josh at bloch.us
Fri Jul 21 11:10:38 EDT 2006


> Ok, else, ArrayList used toArray() in its constructor that takes a
> collection,
> but ArrayDeque doesn't do the same trick, is there a reason ?
> The code can be something like this one :
> public ArrayDeque(Collection<? extends E> c) {
>         int size=c.size();
>         allocateElements(size);
>         c.toArray(elements);
>         tail=size;
> }

Yes, there is a reason:  internally, ArrayDeque instances have arrays
whose size are a power of two, so the aforementioned trick wouldn't


More information about the Concurrency-interest mailing list