java.util.concurrent.ConcurrentLinkedDeque.pollLast()是Java中的內置方法,它檢索此雙端隊列的最後一個元素並將其刪除。如果雙端隊列為空,則該方法返回NULL。
用法:
Conn_Linked_Deque.pollLast()
參數:該函數不接受任何參數。
返回值:該函數返回此雙端隊列的最後一個元素。如果此雙端隊列為空,則該函數返回NULL。
以下示例程序旨在說明pollFirst()方法的使用:
示例1:此程序涉及帶有Integer元素的雙端隊列。
/* Java Program Demonstrate pollLast()
method of ConcurrentLinkedDeque */
import java.util.concurrent.*;
class ConcurrentLinkedDequeDemo {
public static void main(String[] args)
{
ConcurrentLinkedDeque<Integer> cld =
new ConcurrentLinkedDeque<Integer>();
cld.addFirst(12);
cld.addFirst(70);
cld.addFirst(1009);
cld.addFirst(475);
// Displaying the existing LinkedDeque
System.out.println("Elements in"
+ "the LinkedDeque: " + cld);
// Display and remove the Last element
System.out.println("Element removed : "
+ cld.pollLast());
// Displaying the elements
System.out.println("Elements in"
+ "the LinkedDeque: " + cld);
}
}
輸出:
Elements inthe LinkedDeque: [475, 1009, 70, 12] Element removed : 12 Elements inthe LinkedDeque: [475, 1009, 70]
示例2:該程序涉及帶有String元素的雙端隊列。
/* Java Program Demonstrate pollLast()
method of ConcurrentLinkedDeque */
import java.util.concurrent.*;
class ConcurrentLinkedDequeDemo {
public static void main(String[] args)
{
ConcurrentLinkedDeque<String> cld =
new ConcurrentLinkedDeque<String>();
cld.addFirst("GFG");
cld.addFirst("Geeks");
cld.addFirst("Gfg");
cld.addFirst("Geeks");
// Displaying the existing LinkedDeque
System.out.println("Elements in"
+ "the LinkedDeque: " + cld);
// Display and remove the Last element
System.out.println("Element removed : "
+ cld.pollLast());
// Displaying the elements
System.out.println("Elements in"
+ "the LinkedDeque: " + cld);
}
}
輸出:
Elements inthe LinkedDeque: [Geeks, Gfg, Geeks, GFG] Element removed : GFG Elements inthe LinkedDeque: [Geeks, Gfg, Geeks]
參考:https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html#pollLast()
相關用法
- Java LinkedBlockingDeque pollLast()用法及代碼示例
- Java TreeSet pollLast()用法及代碼示例
- Java NavigableSet pollLast()用法及代碼示例
- Java ArrayDeque pollLast()用法及代碼示例
- Java ConcurrentSkipListSet pollLast()用法及代碼示例
- Java BlockingDeque pollLast()用法及代碼示例
- Java ConcurrentLinkedDeque add()用法及代碼示例
- Java ConcurrentLinkedDeque removeFirstOccurrence()用法及代碼示例
- Java ConcurrentLinkedDeque pop()用法及代碼示例
- Java ConcurrentLinkedDeque removeLastOccurrence()用法及代碼示例
- Java ConcurrentLinkedDeque poll()用法及代碼示例
- Java ConcurrentLinkedDeque element()用法及代碼示例
- Java ConcurrentLinkedDeque getLast()用法及代碼示例
- Java ConcurrentLinkedDeque hashCode()用法及代碼示例
- Java ConcurrentLinkedDeque equals()用法及代碼示例
注:本文由純淨天空篩選整理自RICHIK BHATTACHARJEE大神的英文原創作品 ConcurrentLinkedDeque pollLast() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。