Previously we have discussed about
Here we learn What is Deque interface in Java.But Before That you must Know What is Collection Interface in Java ?
Interface Deque<E>
Type Parameters:
E - the type of elements held in this collection
All Superinterfaces:
Collection<E>, Iterable<E>, Queue<E>
All Known Subinterfaces:
BlockingDeque<E>
All Known Implementing Classes:
ArrayDeque, ConcurrentLinkedDeque, LinkedBlockingDeque, LinkedList
Declaration of Deque Interface :
public interface Deque<E>
extends Queue<E>
Deque extends Queue Interface.The name Deque is short for "double ended queue" and is usually pronounced "deck".
This interface supports element insertion and removal at both ends.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).
First Element(Head)
|
Last Element(Tail)
|
Throws exception
|
Special value
|
Throws exception
|
Special value
|
|
Insert
|
addFirst(e)
|
offerFirst(e)
|
addLast(e)
|
offerLast(e)
|
Remove
|
removeFirst()
|
pollFirst()
|
removeLast()
|
pollLast()
|
Examine
|
getFirst()
|
peekFirst()
|
getLast()
|
peekLast()
|
Deque function as standard ,first in-first out queue or as last in-first out.The methods inherited from the Queue interface are precisely equivalent to Deque methods as indicated in the following table:
Queue Method
|
Deque Method
|
add(e)
|
addLast(e)
|
offer(e)
|
offerLast(e)
|
remove()
|
removeFirst()
|
poll()
|
pollFirst()
|
element()
|
getFirst()
|
peek()
|
peekFirst()
|
Deques can also be used as LIFO (Last-In-First-Out) stacks. This interface should be used in preference to the legacy Stack class. When a deque is used as a stack, elements are pushed and popped from the beginning of the deque. Stack methods are precisely equivalent to Deque methods as indicated in the table below:
Stack Method
|
Deque Method
|
push(e)
|
addFirst(e)
|
pop()
|
removeFirst()
|
peek()
|
peekFirst()
|
This interface is a member of the Java Collections Framework.
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