What is the Difference Between Queue and Stack Data Structures in Java ?

Queue is a FIFO data structure. FIFO stands for First In First Out. It means the element added first will be removed first from the queue. A real world example of Queue is a line for buying tickets at a station. The person entering first in the Queue is served first.

Stack is a LIFO data structure. LIFO stands for Last In First Out. The element that is added last is removed first from the collection. In a Stack elements are added or removed from the top of stack.

A real world example of Stack is back button in browser. We can go back one by one only and it works in the reverse order of adding webpages to history.



You May Interest

What is the Difference Between Abstract Class and Interface in Ja ...

What are the Disadvantages of Multithreading in Java ?

What is the Difference Between init-param and context-param in JS ...

How Will You Use a Cookie in JSP ?

Why Did Oracle Release a New Version of Java Like Java 8 ?