LinkedTransferQueue add() method in Java
The add() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which is used to insert an element in this queue.
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.
Parameters: The function accepts a single parameter e i.e. the element to be inserted.
Return Value: The function returns a boolean value.
Exception: The function throws NullPointerException when the specified element is Null.
Below programs illustrate the use of java.util.concurrent.LinkedTransferQueue.add() :
Program 1: Inserting Integers in the queue.
The elements in the queue are: 10 11 12 13 14 15
Program 2: Adding String in the queue.
The elements in the queue are: a b c d e
Program 3: To demonstrate NullPointerException