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:

  1. addFirst(E e): Adds the specified element to the front of the deque.

  2. addLast(E e): Adds the specified element to the end of the deque.

  3. offerFirst(E e): Inserts the specified element at the front of the deque, returning true upon success and false if the deque is full.

  4. offerLast(E e): Inserts the specified element at the end of the deque, returning true upon success and false if the deque is full.

  5. removeFirst(): Removes and returns the first element of the deque, throwing a NoSuchElementException if the deque is empty.

  6. removeLast(): Removes and returns the last element of the deque, throwing a NoSuchElementException if the deque is empty.

  7. pollFirst(): Retrieves and removes the first element of the deque, returning null if the deque is empty.

  8. pollLast(): Retrieves and removes the last element of the deque, returning null if the deque is empty.

  9. getFirst(): Retrieves, but does not remove, the first element of the deque, throwing a NoSuchElementException if the deque is empty.

  10. getLast(): Retrieves, but does not remove, the last element of the deque, throwing a NoSuchElementException if the deque is empty.

  11. peekFirst(): Retrieves, but does not remove, the first element of the deque, returning null if the deque is empty.

  12. peekLast(): Retrieves, but does not remove, the last element of the deque, returning null if the deque is empty.

  13. size(): Returns the number of elements in the deque.

  14. isEmpty(): Returns true if the deque contains no elements.

  15. clear(): Removes all elements from the deque.