Stack stack = new Stack() is not recommended.

and
Deque deque = new ArrayDeque<>(); is a better way

but keep in mind that the method of deque is quite different than stack.

but why deque is better than stack?

  1. Object oriented design - Inheritance, abstraction, classes and interfaces: Stack is a class, Deque is an interface. Only one class can be extended, whereas any number of interfaces can be implemented by a single class in Java (multiple inheritance of type). Using the Deque interface removes the dependency on the concrete Stack class and its ancestors and gives you more flexibility, e.g. the freedom to extend a different class or swap out different implementations of Deque (like LinkedList, ArrayDeque).
  2. Inconsistency: Stack extends the Vector class, which allows you to access element by index. This is inconsistent with what a Stack should actually do, which is why the Deque interface is preferred (it does not allow such operations)–its allowed operations are consistent with what a FIFO or LIFO data structure should allow.
  3. Performance: The Vector class that Stack extends is basically the “thread-safe” version of an ArrayList. The synchronizations can potentially cause a significant performance hit to your application. Also, extending other classes with unneeded functionality (as mentioned in #2) bloat your objects, potentially costing a lot of extra memory and performance overhead.

also, there are two ways to implement interface deque: LinkedList and ArrayDeque.
which means:
Deque<> stack = new ArrayDeque<> ();
Deque<> stack = new LinkedList<>();
and we better choose the first one, because “ArrayDeque(几乎专门是) 实现的是Deque 这个接口, linkedlist 本身是更加底层的实现List 接口的,它还实现了很多Deque 用不上的东西,封装的比较底层,不够前者那么抽象”

the methods of deque,
and maybe we should choose offer/poll/peek
how to initialize a stack?_封装