02 Stack Java Built In

The Stack class represents a LAST-IN-FIRST-OUT (LIFO) stack of objects. It extends class Vector with five operations that allow a vector to be treated as a stack.

The usual POP and PUSH operations as well as PEEK to see top item on the stack and EMPTY to test if it has anything and SEARCH to discover items.

When a STACK is created first, it contains no items.

Java team recommend not to use Stack class but,

A more complete and consistent set of LIFO stack operations is provided by DEQUE interface and its implementations, which should be used in preference to this class.

Ex.

Deque<Integer> stack = new ArrayDeque<Integer>():

or,

LinkedList → but it has add and other stuff then just pop, push, peek so you need to limit only using that when using for stack.