ArrayDeque poll() Method in Java Last Updated : 10 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The java.util.ArrayDeque.poll() method in Java is used to retrieve or fetch and remove the element present at the head of the Deque. The peek() method only retrieved the element at the head but the poll() also removes the element along with the retrieval. It returns NULL if the deque is empty. Syntax: Array_Deque.poll() Parameters: The method does not take any parameter. Return Value: The method removes the element at the head of the Deque and returns the same. It returns NULL if the deque is empty. Below programs illustrate the Java.util.ArrayDeque.poll() method: Program 1: Java // Java code to illustrate poll() 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 into the Deque de_que.add("Welcome"); de_que.add("To"); de_que.add("Geeks"); de_que.add("4"); de_que.add("Geeks"); // Displaying the ArrayDeque System.out.println("ArrayDeque: " + de_que); // Displaying the head System.out.println("The element at head is: " + de_que.poll()); // Displaying the final ArrayDeque System.out.println("ArrayDeque after operation: " + de_que); } } Output: ArrayDeque: [Welcome, To, Geeks, 4, Geeks] The element at head is: Welcome ArrayDeque after operation: [To, Geeks, 4, Geeks] Program 2: Java // Java code to illustrate poll() 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("ArrayDeque: " + de_que); // Displaying the head System.out.println("The element at head is: " + de_que.poll()); // Displaying the final ArrayDeque System.out.println("ArrayDeque after operation: " + de_que); } } Output: ArrayDeque: [10, 15, 30, 20, 5] The element at head is: 10 ArrayDeque after operation: [15, 30, 20, 5] Program 3: For an empty deque: Java // Java code to illustrate poll() import java.util.*; public class ArrayDequeDemo { public static void main(String args[]) { // Creating an empty ArrayDeque Deque<Integer> de_que = new ArrayDeque<Integer>(); // Displaying the ArrayDeque System.out.println("ArrayDeque: " + de_que); // Displaying the head System.out.println("The element at head is: " + de_que.poll()); } } Output: ArrayDeque: [] The element at head is: null Comment More infoAdvertise with us Next Article ArrayDeque poll() 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 iterator() Method in Java The Java.util.ArrayDeque.iterator() method is used to return an iterator of the elements of the ArrayDeque. Syntax: Iterator iterate_value = Array_Deque.iterator(); Parameters: The method does not take any parameter. Return Value: The method iterates over the elements of the deque and returns the va 2 min read ArrayDeque descendingIterator() Method in Java The Java.util.ArrayDeque.descendingIterator() method is used to return an iterator of the same elements as the ArrayDeque but in the reverse order. Syntax: Iterator iterate_value = Array_Deque.descendingIterator(); Parameters: The method does not take any parameter. Return Value: The method iterates 2 min read ArrayDeque element() Method in Java The java.util.ArrayDeque.element() method in Java is used to retrieve or fetch the head of the ArrayDeque. In the process, the method does not delete the element from the deque instead it just returns the element. Syntax: Array_Deque.element() Parameters: The method does not take any parameter. Retu 2 min read 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 Like