[concurrency-interest] Questions about ArrayDeque

Gregg Wonderly gregg at cytetech.com
Fri Jul 21 12:07:58 EDT 2006

Joshua Bloch wrote:
> Rémi,
>>Ok, else, ArrayList used toArray() in its constructor that takes a
>>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
> work.

It should be easy enough to find the correct power of two for allocating right? 
  Then the APIs would be consistent.  These odd implementation details creeping 
into the visible API really adds a lot of confusion.

Someones going to write some code to make it possible for them to stuff a 
Collection in.  Surely there's value in the class already having such an 

Gregg Wonderly

More information about the Concurrency-interest mailing list