LinkedTransferQueue take() method in Java
The java.util.concurrent.LinkedTransferQueue.take() method is an in-built function in Java which retrieves and remove the first element of the queue. This method also waits (if necessary) until an element becomes available.
Parameters: The function does not accept any parameter.
Return Value: The function returns the first element of the queue.
Exceptions: The function throws InterruptedException if interrupted while waiting.
Below programs illustrate the java.util.concurrent.LinkedTransferQueue.take() :
Elements are : Alex Bob Chuck Drake Eric Queue Size: 0
Elements are : 1 2 3 4 5 Queue Size: 0
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.