Java DequeA deque is a linear collection that supports insertion and deletion of elements from both the ends. The name 'deque' is an abbreviation for double-ended queue. There are no fixed limits on the deque for the number of elements they may contain. However, this interface supports capacity restricted deques as well as the deques with no fixed size limits. There are various methods which are provided to insert, remove and examine the elements. These methods typically exist in two forms: the one that throws an exception when the particular operation fails and the other returns a special value which can be either null or false depending upon the operations. MethodsThe java.util.Deque interface provides methods to perform the operations of double-ended queue in Java. Its implementation class is java.util.ArrayDeque.
Example 1Test it NowOutput: Inserting three elements : 1 2 3 After popping : 2 3 Removing the element 3 :[2] Example 2Test it NowOutput: The first element is : [Java] After adding the next element in the front of the deque : [Python, Java] The final deque is : [Python, Java, Ruby] The number of elements are : 3 Deque after removing the last element is given as : [Python, Java] Next TopicJava Deque |