In this shot, we will discuss the Deque.push()
method, where Deque
means the Double Ended Queue, which means it contains push()
and some other methods of LinkedList
. The Deque.push()
method is present in the Deque
interface inside the java.util
package.
The Deque.push(element)
method is used to insert the element at the top of the Deque
.
void Deque.push()
The Deque.push(element)
method takes one parameter:
Element
: This is the element to be inserted at top of the Deque
.The Deque.push()
method doesn’t return anything.
Let’s look at the code snippet below.
import java.util.Deque;import java.util.LinkedList;class Main {public static void main(String[] args){Deque<Integer> objDeque = new LinkedList<Integer>();objDeque.add(212);objDeque.add(23);objDeque.add(621);objDeque.add(1280);objDeque.add(3121);objDeque.add(18297);objDeque.add(791);objDeque.push(7189);objDeque.push(314);System.out.println("Elements in the deque are: " + objDeque);}}
Deque
and LinkedList
) from java.util
.Main
class.main
function.Deque
consisting of Integer
type elements.Deque.add()
method, which inserts the element at the end of the Deque
just like enqueue()
.Deque.push()
method.objDeque
elements by implicitly calling its toString()
.In this way, we can use the Deque.push()
method in Java.