- Used to represent a group of individual objects where all objects are present prior to processing.
- Queue is the child interface of collection.
- Queue Interface and all its implementation classes came in java 1.5 into collections.
Implementation Classes for Queue :
- PriorityQueue
- BlockingQueue
- LinkedBlockingQueue
- PriorityBlockingQueue
Features of Queue :
- When we need to implement logic in first in first out (FIFO) methodology.
- We can change the logic of queue based on requirement like Blocking, priority etc.
Method
- offer(Object o)
- Adding an object to queue
- poll()
- Remove and return the head element of queue
- remove()
- Remove and return the head element of queue
- If queue is empty, it gives Null pointer exception
- peek()
- Return the head element of queue
- element()
- Return the head element of queue
- If queue is empty, it gives No such element exception