java.util.concurrent.ConcurrentLinkedDeque.addLast()是Java中的內置函數,它將指定的元素插入雙端隊列的末尾。
用法:
conn_linked_deque.addLast(elem)
參數:該方法僅接受要添加到ConcurrentLinkedDeque末尾的單個參數elem。
返回值:該函數沒有返回值。
異常:當傳遞給函數的參數為null時,該方法將引發NullPointerException。由於其有限的性質,此方法將永遠不會引發IllegalStateException或返回false。
以下程序說明了java.util.concurrent.ConcurrentLinkedDeque.addLast()方法的用法:
示例1:該程序涉及一個Integer類型的ConcurrentLinkedDeque。
// Java Program Demonstrate addLast()
// method of ConcurrentLinkedDeque
import java.util.concurrent.*;
class ConcurrentLinkedDequeDemo {
public static void main(String[] args)
{
ConcurrentLinkedDeque<Integer> cld =
new ConcurrentLinkedDeque<Integer>();
cld.addLast(12);
cld.addLast(110);
cld.addLast(55);
cld.addLast(76);
// Displaying the existing LinkedDeque
System.out.println("Initial Elements in"
+ "the LinkedDeque: " + cld);
// Insert a new element in the LinkedDeque
cld.addLast(21);
// Displaying the modified LinkedDeque
System.out.println("Initial Elements in"
+ "the LinkedDeque: " + cld);
}
}
輸出:
Initial Elements inthe LinkedDeque: [12, 110, 55, 76] Initial Elements inthe LinkedDeque: [12, 110, 55, 76, 21]
示例2:當將null作為參數傳遞給函數時,此程序涉及一個帶有異常處理的Integer類型的ConcurrentLinkedDeque。
// Java Program Demonstrate addLast()
// method of ConcurrentLinkedDeque
import java.util.concurrent.*;
class ConcurrentLinkedDequeDemo {
public static void main(String[] args)
{
ConcurrentLinkedDeque<String> cld =
new ConcurrentLinkedDeque<String>();
cld.addLast("Geeks");
cld.addLast("Geek");
cld.addLast("Gfg");
cld.addLast("Contribute");
// Displaying the existing LinkedDeque
System.out.println("Initial Elements in"
+ "the LinkedDeque: " + cld);
/* Exception thrown when null
is passed as parameter*/
try {
cld.addLast(null);
}
catch (NullPointerException e) {
System.out.println("NullPointerException"
+ "thrown");
}
// Insert a new element in the LinkedDeque
cld.addLast("Sudo Placement");
// Displaying the modified LinkedDeque
System.out.println("Initial Elements in"
+ "the LinkedDeque: " + cld);
}
}
輸出:
Initial Elements inthe LinkedDeque: [Geeks, Geek, Gfg, Contribute] NullPointerExceptionthrown Initial Elements inthe LinkedDeque: [Geeks, Geek, Gfg, Contribute, Sudo Placement]
參考: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html#addLast()
相關用法
- Java LinkedBlockingDeque addLast()用法及代碼示例
- Java LinkedList addLast()用法及代碼示例
- Java Deque addLast()用法及代碼示例
- Java ArrayDeque addLast()用法及代碼示例
- Java BlockingDeque addLast()用法及代碼示例
- Java ConcurrentLinkedDeque add()用法及代碼示例
- Java ConcurrentLinkedDeque removeLast()用法及代碼示例
- Java ConcurrentLinkedDeque peekFirst()用法及代碼示例
- Java ConcurrentLinkedDeque removeLastOccurrence()用法及代碼示例
- Java ConcurrentLinkedDeque pollFirst()用法及代碼示例
- Java ConcurrentLinkedDeque toArray()用法及代碼示例
- Java ConcurrentLinkedDeque pollLast()用法及代碼示例
- Java ConcurrentLinkedDeque peekLast()用法及代碼示例
- Java ConcurrentLinkedDeque iterator()用法及代碼示例
- Java ConcurrentLinkedDeque removeFirstOccurrence()用法及代碼示例
注:本文由純淨天空篩選整理自RICHIK BHATTACHARJEE大神的英文原創作品 ConcurrentLinkedDeque addLast() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。