Which class from the Java runtime environment you should use when you need a stack.
contains a few classes suitable for pushing, poping, and
peeking in stack style.
the widely used and known interface
Let's see how efficient are the implementations in JRE6, in relative units.
ArrayDeque is best
both in terms of time and speed. If you need a subtype of
List then go with
ArrayList. If you want
to eat memory like crazy for no good reason then try
LinkedList. And if you
have a thing for names like
Stack extends) then,
well, go for it. Just don't say I told you to use it.
Finally, if you are a speed junkie and you know in advance the
maximum possible size of the stack, then you can implement
your own for a x1.2 speed-up (compared to
Just for the record, a basic stack operation for
ArrayDeque takes about 15ns on my
Good bye, and stay tuned for the next useless microbenchmark results.