The java.util.concurrent.ConcurrentLinkedDeque.add() is an in-built function in Java which inserts the specified element at the end of the deque.
Parameter: The method accepts only a single parameter elem which is to be added to tail of the ConcurentLinkedDeque.
Return Value: The function has no return value.
Exception:The method will throw NullPointerException when the parameter passed to the function is null. Due to its bounded nature, this method will never throw IllegalStateException or return false.
Below programs illustrate the ConcurrentLinkedDeque.add() method:
Program 1: This program involves a ConcurrentLinkedDeque of Integer type.
Initial Elements inthe LinkedDeque: [12, 110, 55, 76] Initial Elements inthe LinkedDeque: [12, 110, 55, 76, 21]
Program 2: This program involves a ConcurrentLinkedDeque of String type with Exception Handling when null is passed as parameter to the function.
Initial Elements inthe LinkedDeque: [Gfg, GFG, Geeksforgeeks, Contribute] NullPointerExceptionthrown Initial Elements inthe LinkedDeque: [Gfg, GFG, Geeksforgeeks, Contribute, Geek Classes]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.