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 are the Disadvantages of Multithreading in Java ?

Why an Object Used as Key in HashMap Should Be Immutable in Java ...

How Will You Use a Cookie in JSP ?

What is the Use of Jsp:useBean in JSP ?

When Do You Use Exception or Error in Java ?