Java ArrayBlockingQueue take() MethodThe take() method of Java ArrayBlockingQueue class retrieves and removes the first element of the ArrayBlockingQueue, waiting (if necessary) until an element becomes available. Syntax:Parameters:NA Specified By:The take() method of ArrayBlockingQueue class is specified by:
Return Value:The take() method returns the first element of this queue. Example 1Output: Elements are : 67 109 98 123 100 Queue = [] Example 2Output: Vinni has passed. Rima has passed. Example 3Output: Error:(18, 42) java: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown 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-arrayblockingqueue-tostring-method |
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