drainTo

abstract fun drainTo(c: MutableCollection<E>): Int

Removes all available elements from this queue and adds them to the given collection. This operation may be more efficient than repeatedly polling this queue. A failure encountered while attempting to add elements to collection c may result in elements being in neither, either or both collections when the associated exception is thrown. Attempts to drain a queue to itself result in IllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.

Return

the number of elements transferred

Parameters

c

the collection to transfer elements into

Throws

if addition of elements is not supported by the specified collection

if the class of an element of this queue prevents it from being added to the specified collection

if the specified collection is null

if the specified collection is this queue, or some property of an element of this queue prevents it from being added to the specified collection


abstract fun drainTo(c: MutableCollection<E>, maxElements: Int): Int

Removes at most the given number of available elements from this queue and adds them to the given collection. A failure encountered while attempting to add elements to collection c may result in elements being in neither, either or both collections when the associated exception is thrown. Attempts to drain a queue to itself result in IllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.

Return

the number of elements transferred

Parameters

c

the collection to transfer elements into

maxElements

the maximum number of elements to transfer

Throws

if addition of elements is not supported by the specified collection

if the class of an element of this queue prevents it from being added to the specified collection

if the specified collection is null

if the specified collection is this queue, or some property of an element of this queue prevents it from being added to the specified collection