img
that only a limited number of elements can be added to the deque. When this is the case, an
attempt to add an element to the deque can fail. Deque allows you to handle such a failure in
two ways. First, methods such as addFirst( ) and addLast( ) throw an IllegalStateException if a
Method
Description
void addFirst(E obj)
Adds obj to the head of the deque. Throws an IllegalStateException
if a capacity-restricted deque is out of space.
void addLast(E obj)
Adds obj to the tail of the deque. Throws an IllegalStateException
if a capacity-restricted deque is out of space.
Iterator<E> descendingIterator( )
Returns an iterator that moves from the tail to the head of the
deque. In other words, it returns a reverse iterator.
E getFirst( )
Returns the first element in the deque. The object is not removed
from the deque. It throws NoSuchElementException if the deque
is empty.
E getLast( )
Returns the last element in the deque. The object is not removed
from the deque. It throws NoSuchElementException if the deque is
empty.
boolean of ferFirst(E obj)
Attempts to add obj to the head of the deque. Returns true if
obj was added and false other wise. Therefore, this method
returns false when an attempt is made to add obj to a full,
capacity-restricted deque.
boolean of ferLast(E obj)
Attempts to add obj to the tail of the deque. Returns true if obj
was added and false other wise.
E peekFirst( )
Returns the element at the head of the deque. It returns null if
the deque is empty. The object is not removed.
E peekLast( )
Returns the element at the tail of the deque. It returns null if the
deque is empty. The object is not removed.
E pollFirst( )
Returns the element at the head of the deque, removing the
element in the process. It returns null if the deque is empty.
E pollLast( )
Returns the element at the tail of the deque, removing the
element in the process. It returns null if the deque is empty.
E pop( )
Returns the element at the head of the deque, removing it in the
process. It throws NoSuchElementException if the deque is empty.
void push(E obj )
Adds obj to the head of the deque. Throws an IllegalStateException
if a capacity-restricted deque is out of space.
E removeFirst( )
Returns the element at the head of the deque, removing the
element in the process. It throws NoSuchElementException if
the deque is empty.
Removes the first occurrence of obj from the deque. Returns true
boolean
removeFirstOccurrence(Object obj)
if successful and false if the deque did not contain obj.
E removeLast( )
Returns the element at the tail of the deque, removing the element
in the process. It throws NoSuchElementException if the deque
is empty.
Removes the last occurrence of obj from the deque. Returns true
boolean
removeLastOccurrence(Object obj)
if successful and false if the deque did not contain obj.
TABLE 17-6
The Methods Defined by Deque
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home