Random access in ArrayDeque
daniel.smith at oracle.com
Fri Feb 7 17:44:05 UTC 2014
I noticed recently that the javac scanner is making use of ArrayList.remove(0) when it consumes a buffer. Obviously this is an inefficient way to implement a buffer, so I thought I'd try to fix it . ArrayDeque seems to provide just the behavior I need, with one fatal flaw: despite encoding its data with an array, the class exposes no random-access operations. For lookahead, I need to be able to call get(int).
This seems to be a fairly common complaint .
I found an old bug requesting that ArrayDeque be enhanced to implement List , as well as a thread from 2010 that included a proof-of-concept ArrayDeque+List  and had a note from Martin Buchholz saying he regrets that ArrayDeque doesn't already implement List .
Is there any hope of ArrayDeque being enhanced in the near future to provide random access? There's some risk that any such initiative would be derailed by a quest for an uber-collection. I think a lot of people would be quite happy just to have a (trivial) 'get(int)' method added to ArrayDeque.
More information about the core-libs-dev