Previously we have discussed about
Here we learn What is Queue interface in Java.But Before That you must Know What is Collection Interface in Java ?
Interface Queue<E>
Type Parameters:
E - the type of elements held in this collection
All Superinterfaces:
Collection<E>, Iterable<E>
All Known Subinterfaces:
BlockingDeque<E>, BlockingQueue<E>, Deque<E>, TransferQueue<E>
All Known Implementing Classes:
AbstractQueue, ArrayBlockingQueue, ArrayDeque, ConcurrentLinkedDeque, LinkedList, ConcurrentLinkedQueue, DelayQueue, LinkedBlockingDeque, LinkedBlockingQueue, LinkedTransferQueue, PriorityBlockingQueue, PriorityQueue, SynchronousQueue
Declaration of Queue Interface :
public interface Queue<E>
extends Collection<E>
A Queue is a collection for holding elements prior to processing.Queue order elements in FIFO(First In,First Out).
Besides basic Collection operations, queues provide additional insertion, extraction, and inspection operations. Each of these methods exists in two forms: one throws an exception if the operation fails, the other returns a special value (either null or false, depending on the operation).
Operation Type
|
Throws Exception
|
Returns Special Value
|
Insert
|
add(e)
|
offer(e)
|
Remove
|
remove()
|
poll()
|
Examine
|
element()
|
peek()
|
Head element of the queue is removed by calling remove() or poll() method.And new elements can be inserted from tail of queue.
The remove() and poll() method behavior differ when the queue is empty i.e the remove() method throws an exception, while poll() method returns null.
This interface is a member of the Java Collections Framework.
Method Summary of Queue Interface :
Modifier and Method Name
|
Description
|
boolean add(E e)
|
Inserts the specified element into this queue if
it is possible to do so immediately without violating capacity restrictions,
returning true upon success and throwing an IllegalStateException if no space
is currently available.
|
E element()
|
Retrieves, but does not remove, the head of this
queue.
|
boolean offer(E e)
|
Inserts the specified element into this queue if
it is possible to do so immediately without violating capacity restrictions.
|
E peek()
|
Retrieves, but does not remove, the head of this
queue, or returns null if this queue is empty.
|
E poll()
|
Retrieves and removes the head of this queue, or
returns null if this queue is empty.
|
E remove()
|
Retrieves and removes the head of this queue.
|
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Java I/O Tutorial

No comments:
Post a Comment