The java.util.concurrent.ConcurrentLinkedDeque.addFirst() is an in-built function in Java which inserts the specified element at the front of the ConcurrentLinkedDeque.
Parameter: The method accepts only a single parameter elem which is to be added to the beginning of the ConcurrentLinkedDeque.
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.addFirst() method:
Program 1: This program involves a ConcurrentLinkedDeque of Integer type.
Initial Elements inthe LinkedDeque: [76, 55, 110, 12] Initial Elements inthe LinkedDeque: [21, 76, 55, 110, 12]
Program 2: This program involves a ConcurrentLinkedDeque of Integer type with Exception Handling when null is passed as parameter to the function.
Initial Elements inthe LinkedDeque: [Contribute, Gfg, Geek, Geeks] NullPointerExceptionthrown Initial Elements inthe LinkedDeque: [Sudo Placement, Contribute, Gfg, Geek, Geeks]
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.