Java Methods of ArrayDeque
ArrayDeque
is a class in Java that implements the Deque interface using a resizable array. It provides the functionality of both a stack and a queue, and allows elements to be added or removed from both ends.
Here are some of the methods of ArrayDeque
:
addFirst(E e)
: Adds the specified element to the front of the deque.addLast(E e)
: Adds the specified element to the end of the deque.offerFirst(E e)
: Inserts the specified element at the front of the deque, returningtrue
upon success andfalse
if the deque is full.offerLast(E e)
: Inserts the specified element at the end of the deque, returningtrue
upon success andfalse
if the deque is full.removeFirst()
: Removes and returns the first element of the deque, throwing aNoSuchElementException
if the deque is empty.removeLast()
: Removes and returns the last element of the deque, throwing aNoSuchElementException
if the deque is empty.pollFirst()
: Retrieves and removes the first element of the deque, returningnull
if the deque is empty.pollLast()
: Retrieves and removes the last element of the deque, returningnull
if the deque is empty.getFirst()
: Retrieves, but does not remove, the first element of the deque, throwing aNoSuchElementException
if the deque is empty.getLast()
: Retrieves, but does not remove, the last element of the deque, throwing aNoSuchElementException
if the deque is empty.peekFirst()
: Retrieves, but does not remove, the first element of the deque, returningnull
if the deque is empty.peekLast()
: Retrieves, but does not remove, the last element of the deque, returningnull
if the deque is empty.size()
: Returns the number of elements in the deque.isEmpty()
: Returnstrue
if the deque contains no elements.clear()
: Removes all elements from the deque.