Class Overview
An implementation of Deque, backed by an array.
ArrayDeques have no size limit, can not contain null element, and they are
not thread-safe.
All optional operations are supported, and the elements can be any objects.
Summary
Public Constructors |
|
ArrayDeque()
Constructs a new empty instance of ArrayDeque big enough for 16 elements.
|
|
ArrayDeque(int minSize)
Constructs a new empty instance of ArrayDeque big enough for specified number
of elements.
|
|
ArrayDeque(Collection<? extends E> c)
Constructs a new instance of ArrayDeque containing the elements of the
specified collection, with the order returned by the collection's iterator.
|
Public Methods |
boolean
|
add(Object e)
Inserts the element to the tail of the deque.
|
void
|
addFirst(Object e)
|
void
|
addLast(Object e)
|
void
|
clear()
Empty the deque.
|
boolean
|
contains(Object obj)
Returns true if the specified element is in the deque.
|
Iterator<E>
|
descendingIterator()
Returns the iterator in reverse order, from tail to head.
|
E
|
element()
Gets but does not remove the head element of this deque.
|
E
|
getFirst()
Gets but not removes the head element of this deque.
|
E
|
getLast()
Gets but not removes the tail element of this deque.
|
boolean
|
isEmpty()
Returns true if the deque has no elements.
|
Iterator<E>
|
iterator()
Returns the iterator of the deque.
|
boolean
|
offer(Object e)
Inserts the element at the tail of the deque.
|
boolean
|
offerFirst(Object e)
|
boolean
|
offerLast(Object e)
|
E
|
peek()
Gets but not removes the head element of this deque.
|
E
|
peekFirst()
Gets but not removes the head element of this deque.
|
E
|
peekLast()
Gets but not removes the tail element of this deque.
|
E
|
poll()
Gets and removes the head element of this deque.
|
E
|
pollFirst()
Gets and removes the head element of this deque.
|
E
|
pollLast()
Gets and removes the tail element of this deque.
|
E
|
pop()
Pops the head element of the deque, just same as removeFirst().
|
void
|
push(Object e)
|
E
|
remove()
Gets and removes the head element of this deque.
|
boolean
|
remove(Object obj)
Removes the first equivalent element of the specified object.
|
E
|
removeFirst()
Gets and removes the head element of this deque.
|
boolean
|
removeFirstOccurrence(Object obj)
Removes the first equivalent element of the specified object.
|
E
|
removeLast()
Gets and removes the tail element of this deque.
|
boolean
|
removeLastOccurrence(Object obj)
Removes the last equivalent element of the specified object.
|
int
|
size()
Returns the size of the deque.
|
[Expand]
Inherited Methods |
From class
java.util.AbstractCollection
boolean
|
add(E object)
Attempts to add object to the contents of this Collection
(optional).
|
boolean
|
addAll(Collection<? extends E> collection)
Attempts to add all of the objects contained in collection to the
contents of this Collection (optional).
|
void
|
clear()
Removes all elements from this Collection , leaving it empty
(optional).
|
boolean
|
contains(Object object)
Tests whether this Collection contains the specified object.
|
boolean
|
containsAll(Collection<?> collection)
Tests whether this Collection contains all objects contained in the
specified Collection .
|
boolean
|
isEmpty()
Returns if this Collection contains no elements.
|
abstract
Iterator<E>
|
iterator()
Returns an instance of Iterator that may be used to access the
objects contained by this Collection .
|
boolean
|
remove(Object object)
Removes one instance of the specified object from this Collection if
one is contained (optional).
|
boolean
|
removeAll(Collection<?> collection)
Removes all occurrences in this Collection of each object in the
specified Collection (optional).
|
boolean
|
retainAll(Collection<?> collection)
Removes all objects from this Collection that are not also found in
the Collection passed (optional).
|
abstract
int
|
size()
Returns a count of how many objects this Collection contains.
|
Object[]
|
toArray()
Returns a new array containing all elements contained in this
ArrayList .
|
String
|
toString()
Returns the string representation of this Collection .
|
|
From class
java.lang.Object
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
final
Class<?>
|
getClass()
Returns the runtime class of an object.
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait(long timeout, int nanos)
Causes current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object, or some other
thread interrupts the current thread, or a certain amount of real time has
elapsed.
|
final
void
|
wait(long timeout)
Causes current thread to wait until either another thread invokes the
notify() method or the
notifyAll() method for this object, or a specified
amount of time has elapsed.
|
final
void
|
wait()
Causes current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object.
|
|
From interface
java.lang.Iterable
|
From interface
java.util.Collection
abstract
boolean
|
add(E object)
Attempts to add object to the contents of this Collection
(optional).
|
abstract
boolean
|
addAll(Collection<? extends E> collection)
Attempts to add all of the objects contained in Collection to the
contents of this Collection (optional).
|
abstract
void
|
clear()
Removes all elements from this Collection , leaving it empty
(optional).
|
abstract
boolean
|
contains(Object object)
Tests whether this Collection contains the specified object.
|
abstract
boolean
|
containsAll(Collection<?> collection)
Tests whether this Collection contains all objects contained in the
specified Collection .
|
abstract
boolean
|
equals(Object object)
Compares the argument to the receiver, and returns true if they represent the
same object using a class specific comparison.
|
abstract
int
|
hashCode()
Returns an integer hash code for the receiver.
|
abstract
boolean
|
isEmpty()
Returns if this Collection contains no elements.
|
abstract
Iterator<E>
|
iterator()
Returns an instance of Iterator that may be used to access the
objects contained by this Collection .
|
abstract
boolean
|
remove(Object object)
Removes one instance of the specified object from this Collection if
one is contained (optional).
|
abstract
boolean
|
removeAll(Collection<?> collection)
Removes all occurrences in this Collection of each object in the
specified Collection (optional).
|
abstract
boolean
|
retainAll(Collection<?> collection)
Removes all objects from this Collection that are not also found in
the Collection passed (optional).
|
abstract
int
|
size()
Returns a count of how many objects this Collection contains.
|
abstract
<T>
T[]
|
toArray(T[] a)
Returns an array containing all of the elements in this collection; the
runtime type of the returned array is that of the specified array.
|
abstract
Object[]
|
toArray()
Returns an array containing all of the elements in this collection.
|
|
From interface
java.util.Deque
abstract
void
|
addFirst(E e)
Inserts an element at the head of this deque if it dose not violate size
limit immediately.
|
abstract
void
|
addLast(E e)
Inserts an element at the tail of this deque if it dose not violate size
limit immediately.
|
abstract
Iterator<E>
|
descendingIterator()
Returns the iterator in reverse order, from tail to head.
|
abstract
E
|
getFirst()
Gets but not removes the head element of this deque.
|
abstract
E
|
getLast()
Gets but not removes the tail element of this deque.
|
abstract
boolean
|
offerFirst(E e)
Inserts an element at the head of this deque unless it would violate size
limit.
|
abstract
boolean
|
offerLast(E e)
Inserts an element at the tail of this deque unless it would violate size
limit.
|
abstract
E
|
peekFirst()
Gets but not removes the head element of this deque.
|
abstract
E
|
peekLast()
Gets but not removes the tail element of this deque.
|
abstract
E
|
pollFirst()
Gets and removes the head element of this deque.
|
abstract
E
|
pollLast()
Gets and removes the tail element of this deque.
|
abstract
E
|
pop()
Pops the head element of the deque, just same as removeFirst().
|
abstract
void
|
push(E e)
Pushes the element to the deque(at the head of the deque), just same as
addFirst(E).
|
abstract
E
|
removeFirst()
Gets and removes the head element of this deque.
|
abstract
boolean
|
removeFirstOccurrence(Object o)
Removes the first equivalent element of the specified object.
|
abstract
E
|
removeLast()
Gets and removes the tail element of this deque.
|
abstract
boolean
|
removeLastOccurrence(Object o)
Removes the last equivalent element of the specified object.
|
|
From interface
java.util.Queue
abstract
E
|
element()
Gets but does not remove the element at the head of the queue.
|
abstract
boolean
|
offer(E o)
Inserts the specified element into the queue provided that the condition
allows such an operation.
|
abstract
E
|
peek()
Gets but does not remove the element at the head of the queue.
|
abstract
E
|
poll()
Gets and removes the element at the head of the queue, or returns null if there is no element in the queue.
|
abstract
E
|
remove()
Gets and removes the element at the head of the queue.
|
|
Public Constructors
public
ArrayDeque
()
Constructs a new empty instance of ArrayDeque big enough for 16 elements.
public
ArrayDeque
(int minSize)
Constructs a new empty instance of ArrayDeque big enough for specified number
of elements.
Parameters
minSize |
the smallest size of the ArrayDeque
|
public
ArrayDeque
(Collection<? extends E> c)
Constructs a new instance of ArrayDeque containing the elements of the
specified collection, with the order returned by the collection's iterator.
Parameters
c |
the source of the elements |
Public Methods
public
boolean
add
(Object e)
Inserts the element to the tail of the deque.
public
void
addFirst
(Object e)
public
void
addLast
(Object e)
public
boolean
contains
(Object obj)
Returns true if the specified element is in the deque.
Returns
- true if the element is in the deque, false otherwise
public
Iterator<E>
descendingIterator
()
Returns the iterator in reverse order, from tail to head.
Returns
- the reverse order Iterator
public
E
element
()
Gets but does not remove the head element of this deque. It throws an
exception if the deque is empty.
public
E
getFirst
()
Gets but not removes the head element of this deque. This method throws an
exception if the deque is empty.
public
E
getLast
()
Gets but not removes the tail element of this deque. This method throws an
exception if the deque is empty.
public
boolean
isEmpty
()
Returns true if the deque has no elements.
Returns
- true if the deque has no elements, false otherwise
public
Iterator<E>
iterator
()
Returns the iterator of the deque. The elements will be ordered from head to
tail.
public
boolean
offer
(Object e)
Inserts the element at the tail of the deque.
Returns
- true if the operation succeeds or false if it fails.
public
boolean
offerFirst
(Object e)
public
boolean
offerLast
(Object e)
Returns
- true if the operation succeeds or false if it fails
public
E
peek
()
Gets but not removes the head element of this deque. This method returns null
if the deque is empty.
Returns
- the head element or null if the deque is empty
public
E
peekFirst
()
Gets but not removes the head element of this deque. This method returns null
if the deque is empty.
Returns
- the head element or null if the deque is empty
public
E
peekLast
()
Gets but not removes the tail element of this deque. This method returns null
if the deque is empty.
Returns
- the tail element or null if the deque is empty
public
E
poll
()
Gets and removes the head element of this deque. This method returns null if
the deque is empty.
Returns
- the head element or null if the deque is empty
public
E
pollFirst
()
Gets and removes the head element of this deque. This method returns null if
the deque is empty.
Returns
- the head element or null if the deque is empty
public
E
pollLast
()
Gets and removes the tail element of this deque. This method returns null if
the deque is empty.
Returns
- the tail element or null if the deque is empty
public
E
pop
()
Pops the head element of the deque, just same as removeFirst().
public
E
remove
()
Gets and removes the head element of this deque. This method throws an
exception if the deque is empty.
public
boolean
remove
(Object obj)
Removes the first equivalent element of the specified object. If the deque
does not contain the element, it is unchanged and returns false.
Parameters
obj |
the element to be removed |
Returns
- true if the operation succeeds or false if the deque does not contain
the element
public
E
removeFirst
()
Gets and removes the head element of this deque. This method throws an
exception if the deque is empty.
public
boolean
removeFirstOccurrence
(Object obj)
Removes the first equivalent element of the specified object. If the deque
does not contain the element, it is unchanged and returns false.
Parameters
obj |
the element to be removed |
Returns
- true if the operation succeeds or false if the deque does not contain
the element
public
E
removeLast
()
Gets and removes the tail element of this deque. This method throws an
exception if the deque is empty.
public
boolean
removeLastOccurrence
(Object obj)
Removes the last equivalent element of the specified object. If the deque
does not contain the element, it is unchanged and returns false.
Parameters
obj |
the element to be removed |
Returns
- true if the operation succeeds or false if the deque does not contain
the element.
public
int
size
()
Returns the size of the deque.