Queue Interface

Queue Interface –
    In mathematical terms, there is an algorithm which introduce the FIFO (First in First out). Means if you are going to see a musical show, there will be a line of persons and one by one everybody will enter in the hall. It follows First in first out concept.
    Queue interface was introduced for follow the FIFO concept. Queue Interface came in J2SE 5.
    Declaration of Queue is
interface Queue<E>   

Queue interface has five methods:

E element() –
    This method is used for return an element which belongs at the head in Queue. If queue has no element it throws NoSuchElementException.

boolean offer(E e) -
    This method is used for adding a new element in queue. If queue adds this element it returns true otherwise return false.

E peek() –
    This method is used for return an element which belongs at the head in queue. If there is no element in queue, returns null.

E poll() –
    This method is used for delete an element at the head and returns the deleted element. It returns null if queue is empty.

E remove() –
    This method works as same as poll method. Different is that it throws NoSuchElementExcepton if queue is empty.

There are some classes which implements Queue Interface.
•    AbstractQueue
•    ArrayBlockingQueue
•    ConcurrentLinkedQueue
•    DelayQueue
•    LinkedBlockingQueue
•    LinkedList
•    PriorityBlockingQueue
•    PriorityQueue
•    SynchronousQueue

Comments

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

Use of req.query, req.params and req.body in NODE JS

How to capture finger prints in java