Java LinkedTransferQueue take() MethodThe take() method of Java LinkedTransferQueue class retrieves and removes the first element of the LinkedTransferQueue. This method also waits (if necessary) until an element becomes available. Syntax:Parameters:NA Specified By:The take() method of LinkedTransferQueue class is specified by: o take in interface BlockingQueue<E>. Return Value:The take() method returns the first element of this queue. Throws:InterruptedException: This exception will throw if interrupted while waiting. Example 1Test it NowOutput: Elements are : 67 109 98 123 100 Queue = [] Example 2Test it NowOutput: Harry has passed. Peter has passed. Example 3Test it NowOutput: Exception in thread "main" java.lang.Error: Unresolved compilation problem: Unhandled exception type InterruptedException at tests.LinkedTransferQueueTakeExample3.main(LinkedTransferQueueTakeExample3.java:17) Note: To resolve this error, either we should add exception to the method signature or should surround the take() method with try and catch.Next TopicJava LinkedTransferQueue |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India