What is the difference between Stack and Queue in java?

What is Stack?
A Stack is a first-in, last-out data structure that pops elements in the opposite order than they were pushed. By default, a Stack uses an Array for its internal storage, although this can easily be changed.

What is the queue?
A Queue is a first-in, first-out data structure that pops elements in the same order that they were pushed. By default, a Queue uses an SList for its internal storage, although this can easily be changed.

What is the difference between Stack and Queue in java?
1. A Stack represents a Collection of objects that are in LIFO (Last In First Out Order). A Queue is also a Collection of Objects
similar to a Stack.
2. The Stack class provides operations that allow testing for zero elements, inspection of its topmost element, removal of its topmost element, and the addition of elements. Queues typically order the elements contained within in FIFO order but this is not always the case.


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments:

Thanks
Mukesh Rajput