java.util.concurrent.ConcurrentLinkedDeque.peekFirst()是Java中的內置方法,
檢索的第一個元素這個雙端隊列而不刪除它。函數返回空值如果雙端隊列為空。
用法:
Conn_Linked_Deque.peekFirst()
參數:該函數不接受任何參數。
返回值:該函數返回此雙端隊列中存在的第一個元素,當雙端隊列為空時,該函數返回NULL。
以下示例程序旨在說明peekFirst()方法:
示例1:此程序涉及帶有Integer元素的雙端隊列。
// Java Program Demonstrate peekFirst()
// 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(110);
cld.addFirst(55);
cld.addFirst(76);
// Displaying the existing LinkedDeque
System.out.println("Elements in"
+ "the LinkedDeque: " + cld);
// Displaying the first element
System.out.println("First Element in"
+ "the LinkedDeque: " + cld.peekFirst());
}
}
輸出:
Elements inthe LinkedDeque: [76, 55, 110, 12] First Element inthe LinkedDeque: 76
示例2:該程序涉及帶有String元素的雙端隊列。
// Java Program Demonstrate peekFirst()
// 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("Gfg");
cld.addFirst("GeeksforGeeks");
cld.addFirst("Geeks");
// Displaying the existing LinkedDeque
System.out.println("Elements in"
+ "the LinkedDeque: " + cld);
// Displaying the First element
System.out.println("First Element in"
+ "the LinkedDeque: " + cld.peekFirst());
}
}
輸出:
Elements inthe LinkedDeque: [Geeks, GeeksforGeeks, Gfg, GFG] First Element inthe LinkedDeque: Geeks
相關用法
- Java LinkedBlockingDeque peekFirst()用法及代碼示例
- Java ArrayDeque peekFirst()用法及代碼示例
- Java ConcurrentLinkedDeque add()用法及代碼示例
- Java ConcurrentLinkedDeque descendingIterator()用法及代碼示例
- Java ConcurrentLinkedDeque pollLast()用法及代碼示例
- Java ConcurrentLinkedDeque pollFirst()用法及代碼示例
- Java ConcurrentLinkedDeque removeLast()用法及代碼示例
- Java ConcurrentLinkedDeque toArray()用法及代碼示例
- Java ConcurrentLinkedDeque pop()用法及代碼示例
- Java ConcurrentLinkedDeque peek()用法及代碼示例
- Java ConcurrentLinkedDeque poll()用法及代碼示例
- Java ConcurrentLinkedDeque removeFirst()用法及代碼示例
- Java ConcurrentLinkedDeque getFirst()用法及代碼示例
- Java ConcurrentLinkedDeque offerFirst()用法及代碼示例
- Java ConcurrentLinkedDeque offerLast()用法及代碼示例
注:本文由純淨天空篩選整理自RICHIK BHATTACHARJEE大神的英文原創作品 ConcurrentLinkedDeque peekFirst() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。