ConcurrentLinkedDeque pop() method in Java with Examples
The Java.util.ConcurrentLinkedDeque.pop() method in Java is used to pop an element from the ConcurrentLinkedDeque. The element is popped from the top of the ConcurrentLinkedDeque and is removed from the same.
Syntax:
ConcurrentLinkedDeque.pop()
Parameters: The method does not take any parameters.
Return Value: This method returns the element present at the top of the ConcurrentLinkedDeque and then removes it.
Exceptions: The method throws EmptyConcurrentLinkedDequeException is thrown if the ConcurrentLinkedDeque is empty.
Below programs illustrate the Java.util.ConcurrentLinkedDeque.pop() method:
Program 1:
// Java code to illustrate pop() import java.util.*; import java.util.concurrent.*; public class ConcurrentLinkedDequeDemo { public static void main(String args[]) { // Creating an empty ConcurrentLinkedDeque ConcurrentLinkedDeque<String> CLD = new ConcurrentLinkedDeque<String>(); // Use add() method to add elements CLD.push("Welcome"); CLD.push("To"); CLD.push("Geeks"); CLD.push("For"); CLD.push("Geeks"); // Displaying the ConcurrentLinkedDeque System.out.println("Initial ConcurrentLinkedDeque: " + CLD); // Removing elements using pop() method System.out.println("Popped element: " + CLD.pop()); System.out.println("Popped element: " + CLD.pop()); // Displaying the ConcurrentLinkedDeque after pop operation System.out.println("ConcurrentLinkedDeque after pop peration " + CLD); } } |
Initial ConcurrentLinkedDeque: [Geeks, For, Geeks, To, Welcome] Popped element: Geeks Popped element: For ConcurrentLinkedDeque after pop peration [Geeks, To, Welcome]
Program 2:
// Java code to illustrate pop() import java.util.*; import java.util.concurrent.*; public class ConcurrentLinkedDequeDemo { public static void main(String args[]) { // Creating an empty ConcurrentLinkedDeque ConcurrentLinkedDeque<Integer> CLD = new ConcurrentLinkedDeque<Integer>(); // Use add() method to add elements CLD.push(10); CLD.push(15); CLD.push(30); CLD.push(20); CLD.push(5); // Displaying the ConcurrentLinkedDeque System.out.println("Initial ConcurrentLinkedDeque: " + CLD); // Removing elements using pop() method System.out.println("Popped element: " + CLD.pop()); System.out.println("Popped element: " + CLD.pop()); // Displaying the ConcurrentLinkedDeque after pop operation System.out.println("ConcurrentLinkedDeque after pop operation " + CLD); } } |
Initial ConcurrentLinkedDeque: [5, 20, 30, 15, 10] Popped element: 5 Popped element: 20 ConcurrentLinkedDeque after pop operation [30, 15, 10]
Recommended Posts:
- ConcurrentLinkedDeque contains() method in Java with Examples
- ConcurrentLinkedDeque Spliterator() method in Java with Examples
- ConcurrentLinkedDeque remove() method in Java with Examples
- ConcurrentLinkedDeque addAll() method in Java with Examples
- ConcurrentLinkedDeque push() method in Java with Examples
- ConcurrentLinkedDeque offer() method in Java with Examples
- ConcurrentLinkedDeque isEmpty() method in Java with Examples
- ConcurrentLinkedDeque in Java with Examples
- ConcurrentLinkedDeque add() method in Java
- ConcurrentLinkedDeque removeLast() method in Java
- ConcurrentLinkedDeque peek() method in Java with Example
- ConcurrentLinkedDeque peekLast() method in Java
- ConcurrentLinkedDeque pollLast() method in Java
- ConcurrentLinkedDeque getLast() Method in Java
- ConcurrentLinkedDeque pollFirst() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



