A question eerily similar to Why kotlin does not provide LinkedList implementation? - #16 by Wasabi375.
The consideration to not provide a LinkedList
implementation is that an ArrayDeque
provides the same, but faster. This is true. From the JVM documentation on ArrayDeque
:
This class is likely to be faster than Stack when used as a stack, and faster than LinkedList when used as a queue.
I’d like to abstract sandeep549’s question, because I gather he probably doesn’t really care about LinkedList
specifically, but rather an efficient Deque
implementation.
ArrayDeque
is very similar to ArrayList
, but it has a different resizing strategy on the JVM, namely that ArrayDeque
roughly increases its capacity by 2x, whereas ArrayList
does it by 1.5x.
Granted, these performance gains do not matter in the grand scheme of computational complexity, but do matter in practice. I like the ArrayDeque implementation for my mobile application, because it aligns with power-of-two and uses strictly less array copies, resulting in less GC.
This is might be just an implementation detail, but I use a deque to signal that the code should optimize for sequential writes. I think the multi-platform story improves by adding it to stdlib.