Stack by Deque

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.

Deque stack = new ArrayDeque();

or = new LinkedList<>();
A deque is a double ended queue, by definition it is not a stack. It allows LIFO and FIFO behaviour.

reference:https://docs.oracle.com/javase/7/docs/api/java/util/Deque.html
Deque 作为Stack 的基本操作 for now:
void push(e) = addFirst(e) NullPointerException - if the specified element is null
E pop() = removeFirst() NoSuchElementException - if this deque is empty
void peek() = peekFirst() returns null if this deque is empty.

int size()
boolean isEmpty()

你可能感兴趣的:(Stack by Deque)