I've been thinking about this over the past few weeks, and I've come up with no good arguments. My perspective is from Java, but if anyone has any language-specific cases outside of this language, I'd love to hear them.
It seems to me that the benefit of using a List over a Deque comes from the fact that one can access the elements within directly via index numbers. While I can see the use in something like a UI (e.g. having a drag-and-drop sortable list), when talking about pure code interaction I see three cases for this:
Iteration. Iterating with a
for
loop usingget(i)
andsize()
is expensive in most implementations, and can usually be better done withiterator()
, which is present in everyIterable
collection.Lookup by index. This usually requires a table of indices and a fixed length list, in which case one would get better performance out of an array.
Operating on the front or back of a
List
. This is whatDeque
was designed for, and it doesn't require any calls tosize()
.
Collections
support is nice, but the only thing I could find offhand that was implemented in Collections
but not Arrays
was a shuffle()
function, which is fairly simple for an experienced programmer to implement (or delegate to Collections
, since the overhead for non-primitive arrays isn't too bad IMO).
I feel that everything that one would need a List
for can be better filled by either a Deque
or an array. I've done some searching for comparisons, but the only info I've found either doesn't really discuss Deque
s or is written as a "Welcome to Programming" thing and doesn't offer a direct comparison of use cases. I've looked over my code for the past few years and haven't found any List
s outside of UI elements; I usually use a Set
or a BlockingQueue
for storing variable-length data.
Deque
but in Java (at least) arrays have fix size which is simply a nogo in most of my use cases.Deque
.ArrayDeque
is an implementation with about the same performance asArrayList
, andLinkedList
also functions as aDeque
.List
s to arrays for fixed-length data, I'd love to read about it. Programmer opinion, language semantics, and expected behavior are all important factors in choosing a construct. You can feel free to post an answer if you feel like you have enough material for one.java.util.List
withjava.util.Deque
. They are interfaces. Performance is only an issue when you choose an implementation.