`LinkedList` can't be more efficient under any cir...
# stdlib
m
LinkedList
can't be more efficient under any circumstances
3
1
k
If you're constantly adding an removing stuff on the front of the list a
LinkedList
can definitely be faster.
a
You are changing few references instead of moving the elements in the array a step forward?
Which is faster right?
k
Yes.
m
ArrayQueue can do this without bloating and fragmenting heap.
g
Exactly, usually you can find better data structure for any use case than LinkedList
k
Ah and what about
iterator.remove()
and
.add()
? I don't think
ArrayDeque
is good at those either.
g
Nope, but it really depends on case. And cases when LinkedList is the best choice on practice (not in theory) are very limited
m
Copying several hundreds of values inside CPU cache may be faster, than a single
iterator.next()
which requires loading another block of RAM.