What is a Stack in Java?

Java MCQ: What is a Stack in Java?

a) A last-in, first-out (LIFO) data structure
b) A first-in, first-out (FIFO) data structure
c) A collection that does not allow duplicates
d) A collection that maps keys to values

Answer:

a) A last-in, first-out (LIFO) data structure

Explanation:

A Stack in Java is a last-in, first-out (LIFO) data structure, meaning that the last element added is the first one to be removed. It extends the Vector class and provides methods for pushing, popping, and peeking elements.

Understanding stacks is essential for implementing algorithms that require LIFO behavior, such as depth-first search and expression evaluation.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top