From question:
why is it said to favor arrayDequeue?
It is not said to favor ArrayDeque
(a class).
It is said that you should favor Deque
(an interface) over Stack
(a class), because you should program to an interface, allowing you to substitute the implementation without otherwise changing your code.
The "it is said ..." is right there in the javadoc of Stack
:
A more complete and consistent set of LIFO stack operations is provided by the Deque
interface and its implementations, which should be used in preference to this class.
The Java Runtime Library comes with the following choices of implementation for a Deque
:
LinkedBlockingDeque
uses locks, which is similar to using synthronized
, but none of the others use synchronized
. The way ConcurrentLinkedDeque
is implemented to be thread-safe has proven to perform better than an implementation using synchronized
. ArrayDeque
is faster than Stack
because it is not using synchronized
, so is better for non-thread-safe code.
See also: Why should I use Deque over Stack?
See also: Why is Java Vector (and Stack) class considered obsolete or deprecated?