Stack
java.util.Stack
caution
Use ArrayDeque for using Stack :~
The Standard Class Library provides the Stack class, but, according to JavaDoc, 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. So, it is recommended to use Deque for stacks.
caution
Must Use
ArrayDequeclass to declareStackas it contains all the methods of Stack and can also implementQueueas well.
- Stackcannot use- for_Eachloop to traverse through its elements.- Iteratorclass with its methods- .hasNext()&- .next()must be used to print and traverse through all its elements.
- Stackuses- Last In First Out (LIFO)
- Stackcan only use- push()to add elements and- pop()to remove and print elements and