Open In App

Java Program to Implement ArrayDeque API

Last Updated : 19 Jan, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

The ArrayDeque in Java provides how to use resizable-array additionally to the implementation of the Deque interface. It is also referred to as Array Double Ended Queue or Array Deck. This is a special quite array that grows and allows users to feature or remove a component from each side of the queue.

java.lang.Object

    java.util.AbstractCollection<E>

        java.util.ArrayDeque<E>

All implemented interfaces of ArrayDeque in the hierarchy are:

  • Serializable, 
  • Cloneable, 
  • Iterable<E>, 
  • Collection<E>
  • Deque<E> 
  • Queue<E>

Array deques haven't any capacity restrictions; they grow as necessary to support usage. They are not thread-safe; within the absence of external synchronization, they are doing not support concurrent access by multiple threads. Null elements are prohibited. This class is probably going to be faster than Stack when used as a stack, and faster than LinkedList when used as a queue.

Implementation:


Output
Element : 10
Element : 20
Element : 30
Element : 40
Element : 50
Using clear() 
Above elements have been cleared
Elements of deque using Iterator :
291
564
24
14
Print elements in reverse order :
14
24
564
291

Head Element using element(): 291
Getting Head Element using getFirst(): 291
Getting Last Element using getLast(): 14

Array Size : 4
Array elements :  291 564 24 14
Head element : 291
Head element poll : 291
Head element remove : 2365
Final Array: [984, 265, 564, 24, 14]

Next Article

Similar Reads