Java Program to Implement ArrayDeque API
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:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
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.
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]