ArrayDeque pop() Method in Java Last Updated : 10 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The Java.util.ArrayDeque.pop() method in Java is used to pop an element from the deque. The element is popped from the top of the deque and is removed from the same. Syntax: Array_Deque.pop() Parameters: The method does not take any parameters. Return Value: This method returns the element present at the front of the Deque. Exceptions: The method throws NoSuchElementException is thrown if the deque is empty. Below programs illustrate the Java.util.ArrayDeque.pop() method: Program 1: Java // Java code to illustrate pop() import java.util.*; public class ArrayDequeDemo { public static void main(String args[]) { // Creating an empty ArrayDeque Deque<String> de_que = new ArrayDeque<String>(); // Use add() method to add elements de_que.add("Welcome"); de_que.add("To"); de_que.add("Geeks"); de_que.add("For"); de_que.add("Geeks"); // Displaying the ArrayDeque System.out.println("Initial ArrayDeque: " + de_que); // Removing elements using pop() method System.out.println("Popped element: " + de_que.pop()); System.out.println("Popped element: " + de_que.pop()); // Displaying the ArrayDeque after pop System.out.println("Deque after operation " + de_que); } } Output: Initial ArrayDeque: [Welcome, To, Geeks, For, Geeks] Popped element: Welcome Popped element: To Deque after operation [Geeks, For, Geeks] Program 2: Java // Java code to illustrate pop() import java.util.*; public class ArrayDequeDemo { public static void main(String args[]) { // Creating an empty ArrayDeque Deque<Integer> de_que = new ArrayDeque<Integer>(); // Use add() method to add elements into the Deque de_que.add(10); de_que.add(15); de_que.add(30); de_que.add(20); de_que.add(5); // Displaying the ArrayDeque System.out.println("Initial ArrayDeque: " + de_que); // Removing elements using pop() method System.out.println("Popped element: " + de_que.pop()); System.out.println("Popped element: " + de_que.pop()); // Displaying the ArrayDeque after pop System.out.println("Deque after operation " + de_que); } } Output: Initial ArrayDeque: [10, 15, 30, 20, 5] Popped element: 10 Popped element: 15 Deque after operation [30, 20, 5] Comment More infoAdvertise with us Next Article ArrayDeque pop() Method in Java chinmoy lenka Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-ArrayDeque +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads ArrayDeque getFirst() Method in Java The java.util.ArrayDeque.getFirst() method in Java is used to retrieve or fetch the first element of the ArrayDeque. In the process, the method does not delete the element from the deque instead it just returns the first element of the deque. Syntax: Array_Deque.getFirst() Parameters: The method doe 2 min read ArrayDeque getLast() Method in Java The java.util.ArrayDeque.getLast() method in Java is used to retrieve or fetch the last element of the ArrayDeque. In the process, the method does not delete the element from the deque instead it just returns the last element of the deque.Syntax: Array_Deque.getLast() Parameters: The method does not 2 min read ArrayDeque isEmpty() Method in Java The Java.util.ArrayDeque.isEmpty() method in Java is used to check and verify if an ArrayDeque is empty or not. It returns True if the Deque is empty else it returns False. Syntax: Array_Deque.isEmpty() Parameters: The method does not take any parameter. Return Value: The function returns True if th 2 min read ArrayDeque toArray() Method in Java The java.util.ArrayDeque.toArray() method is used to form an array of the same elements as that of the Deque. Basically, the method copies all the element from this deque to a new array. Syntax: Object[] arr = Array_Deque.toArray() Parameters: The method does not take any parameters. Return Value: T 2 min read ArrayDeque offer() Method in Java The Java.util.ArrayDeque.offer(Object element) method in Java is used to add a specific element at the end of the Deque. The function is similar to the offerLast() method of ArrayDeque in Java. Syntax: Array_Deque.offer(Object element) Parameters: The parameter element is of the type ArrayDeque and 2 min read ArrayDeque offerFirst() Method in Java The Java.util.ArrayDeque.offerFirst(Object element) method in Java is used to add a specific element at the front of the Deque. The function is similar to the addFirst() method of ArrayDeque in Java. Syntax: Array_Deque.offerFirst(Object element) Parameters: The parameter element is of the type Arra 2 min read ArrayDeque offerLast() Method in Java The Java.util.ArrayDeque.offerLast(Object element) method in Java is used to add a specific element at the end of this Deque. The function is similar to the addLast(), add() and offer() method of ArrayDeque in Java. Syntax: Array_Deque.offerLast(Object element) Parameters: The parameter element is o 2 min read ArrayDeque peek() Method in Java The java.util.ArrayDeque.peek() method in Java is used to retrieve or fetch the element at the head of the Deque. The element retrieved does not get deleted or removed from the Queue instead the method just returns it. If no element is present in the deque then Null is returned. Syntax: Array_Deque. 2 min read ArrayDeque peekFirst() Method in Java The java.util.ArrayDeque.peekFirst() method in Java is used to retrieve or fetch the first element of the deque. The element retrieved does not get deleted or removed from the Queue instead the method just returns it. If no element is present in the deque or it is empty, then Null is returned. Synta 2 min read ArrayDeque peekLast() Method in Java The java.util.ArrayDeque.peekLast() method in Java is used to retrieve or fetch the last element of the deque. The element retrieved does not get deleted or removed from the Queue instead the method just returns it. If no element is present in the deque or it is empty, then Null is returned. Syntax: 2 min read Like