Java中的Java.util.ConcurrentLinkedDeque.pop()方法用于从ConcurrentLinkedDeque中弹出元素。该元素从ConcurrentLinkedDeque的顶部弹出,并从该元素中删除。
用法:
ConcurrentLinkedDeque.pop()
参数:该方法不带任何参数。
返回值:此方法返回存在于ConcurrentLinkedDeque顶部的元素,然后将其删除。
异常:如果ConcurrentLinkedDeque为空,则抛出EmptyConcurrentLinkedDequeException。
以下程序说明了Java.util.ConcurrentLinkedDeque.pop()方法:
示例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]
示例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]
相关用法
- Java ConcurrentLinkedDeque contains()用法及代码示例
- Java ConcurrentLinkedDeque remove()用法及代码示例
- Java ConcurrentLinkedDeque addAll()用法及代码示例
- Java ConcurrentLinkedDeque isEmpty()用法及代码示例
- Java ConcurrentLinkedDeque offer()用法及代码示例
- Java ConcurrentLinkedDeque push()用法及代码示例
- Java ConcurrentLinkedDeque Spliterator()用法及代码示例
- Java ConcurrentLinkedDeque用法及代码示例
- Java ConcurrentLinkedDeque add()用法及代码示例
- Java ConcurrentLinkedDeque removeFirstOccurrence()用法及代码示例
- Java ConcurrentLinkedDeque getFirst()用法及代码示例
- Java ConcurrentLinkedDeque removeLast()用法及代码示例
- Java ConcurrentLinkedDeque element()用法及代码示例
- Java ConcurrentLinkedDeque removeFirst()用法及代码示例
- Java ConcurrentLinkedDeque poll()用法及代码示例
注:本文由纯净天空筛选整理自MerlynShelley大神的英文原创作品 ConcurrentLinkedDeque pop() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。