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

How Strategy Design Pattern is Different From State Design Patter ...

What are the Main Uses of Singleton Design Pattern in Java ?

What is Hash Collision in Java ?

Why Do We Use finalize Method in Java ?

What are the Differences Between a List and Set Collection in Jav ...