Java ArrayBlockingQueue drainTo() MethodThe drainTo() method of ArrayBlockingQueue() class removes all the elements present in this queue and adds them to the provided collection. Syntax:Parameters:c - This is the collection to which elements are transferred. maxElements - This is the maximum number of elements to be transferred. Specified By:The drainTo() method of ArrayBlockingQueue class is specified by drainTo() method in interface BlockingQueue. Example 1Output: Elements int the queue = [0, 1, 2] Elements left in the queue :[] Elements drained in the list[0, 1, 2] Example 2Output: Elements int the queue = [0, 1, 2, 3] Elements left in the queue : [2, 3] Elements drained in the list : [0, 1] Next TopicJava-arrayblockingqueue-class |
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