# DelayQueue

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/java/util/concurrent/DelayQueue#pubctors)\|[Methods](https://developer.android.com/reference/java/util/concurrent/DelayQueue#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/java/util/concurrent/DelayQueue#inhmethods)  

# DelayQueue

`
public


class
DelayQueue
`  
`


``


``

extends `[AbstractQueue](https://developer.android.com/reference/java/util/AbstractQueue)`<E extends `[Delayed](https://developer.android.com/reference/java/util/concurrent/Delayed)`>


``


implements

`[BlockingQueue](https://developer.android.com/reference/java/util/concurrent/BlockingQueue)`<E extends `[Delayed](https://developer.android.com/reference/java/util/concurrent/Delayed)`>


`

|---|---|---|--------------------------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object)                                                                              ||||
| ↳ | [java.util.AbstractCollection](https://developer.android.com/reference/java/util/AbstractCollection)\<E extends[java.util.concurrent.Delayed](https://developer.android.com/reference/java/util/concurrent/Delayed)\> |||
|   | ↳ | [java.util.AbstractQueue](https://developer.android.com/reference/java/util/AbstractQueue)\<E extends[java.util.concurrent.Delayed](https://developer.android.com/reference/java/util/concurrent/Delayed)\> ||
|   |   | ↳ | java.util.concurrent.DelayQueue\<E extends[java.util.concurrent.Delayed](https://developer.android.com/reference/java/util/concurrent/Delayed)\> |

<br />

*** ** * ** ***

An unbounded[blocking queue](https://developer.android.com/reference/java/util/concurrent/BlockingQueue)of[Delayed](https://developer.android.com/reference/java/util/concurrent/Delayed)elements, in which an element generally becomes eligible for removal when its delay has expired.

An element is considered*expired* when its`getDelay(TimeUnit.NANOSECONDS)`method would return a value less than or equal to zero.

An element is considered the*head*of the queue if it is the element with the earliest expiration time, whether in the past or the future, if there is such an element.

An element is considered the*expired head* of the queue if it is the*expired* element with the earliest expiration time in the past, if there is such an element. The*expired head* , when present, is also the*head*.

While this class implements the`BlockingQueue`interface, it intentionally violates the general contract of`BlockingQueue`, in that the following methods disregard the presence of unexpired elements and only ever remove the*expired head*:

- [poll()](https://developer.android.com/reference/java/util/concurrent/DelayQueue#poll())
- [poll(long, java.util.concurrent.TimeUnit)](https://developer.android.com/reference/java/util/concurrent/DelayQueue#poll(long,%20java.util.concurrent.TimeUnit))
- [take()](https://developer.android.com/reference/java/util/concurrent/DelayQueue#take())
- [remove()](https://developer.android.com/reference/java/util/concurrent/DelayQueue#remove())

All other methods operate on both expired and unexpired elements. For example, the[size()](https://developer.android.com/reference/java/util/concurrent/DelayQueue#size())method returns the count of all elements. Method[peek()](https://developer.android.com/reference/java/util/concurrent/DelayQueue#peek())may return the (non-null)*head* even when`take()`would block waiting for that element to expire.

This queue does not permit null elements.

This class and its iterator implement all of the*optional* methods of the[Collection](https://developer.android.com/reference/java/util/Collection)and[Iterator](https://developer.android.com/reference/java/util/Iterator)interfaces. The Iterator provided in method[iterator()](https://developer.android.com/reference/java/util/concurrent/DelayQueue#iterator())is*not*guaranteed to traverse the elements of the DelayQueue in any particular order.

This class is a member of the[Java Collections Framework](https://reference/java/util/package-summary.html#CollectionsFramework).

## Summary

|                                                                                                                                                                                                 ### Public constructors                                                                                                                                                                                                  ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[DelayQueue](https://developer.android.com/reference/java/util/concurrent/DelayQueue#DelayQueue())`() ` Creates a new`DelayQueue`that is initially empty.                                                                                                                                                                                                                                                          |
| ` `[DelayQueue](https://developer.android.com/reference/java/util/concurrent/DelayQueue#DelayQueue(java.util.Collection<?%20extends%20E>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? extends E> c) ` Creates a`DelayQueue`initially containing the elements of the given collection of[Delayed](https://developer.android.com/reference/java/util/concurrent/Delayed)instances. |

|                                                                                                                                                                                                                                                                                                                          ### Public methods                                                                                                                                                                                                                                                                                                                          ||
|--------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` boolean`                                                                     | ` `[add](https://developer.android.com/reference/java/util/concurrent/DelayQueue#add(E))`(E e) ` Inserts the specified element into this delay queue.                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` void`                                                                        | ` `[clear](https://developer.android.com/reference/java/util/concurrent/DelayQueue#clear())`() ` Atomically removes all of the elements from this delay queue.                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` int`                                                                         | ` `[drainTo](https://developer.android.com/reference/java/util/concurrent/DelayQueue#drainTo(java.util.Collection<?%20super%20E>,%20int))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? super E> c, int maxElements) ` Removes at most the given number of available elements from this queue and adds them to the given collection.                                                                                                                                                                                                               |
| ` int`                                                                         | ` `[drainTo](https://developer.android.com/reference/java/util/concurrent/DelayQueue#drainTo(java.util.Collection<?%20super%20E>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? super E> c) ` Removes all available elements from this queue and adds them to the given collection.                                                                                                                                                                                                                                                               |
| ` `[Iterator](https://developer.android.com/reference/java/util/Iterator)`<E>` | ` `[iterator](https://developer.android.com/reference/java/util/concurrent/DelayQueue#iterator())`() ` Returns an iterator over all the elements (both expired and unexpired) in this queue.                                                                                                                                                                                                                                                                                                                                                                                         |
| ` boolean`                                                                     | ` `[offer](https://developer.android.com/reference/java/util/concurrent/DelayQueue#offer(E))`(E e) ` Inserts the specified element into this delay queue.                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` boolean`                                                                     | ` `[offer](https://developer.android.com/reference/java/util/concurrent/DelayQueue#offer(E,%20long,%20java.util.concurrent.TimeUnit))`(E e, long timeout, `[TimeUnit](https://developer.android.com/reference/java/util/concurrent/TimeUnit)` unit) ` Inserts the specified element into this delay queue.                                                                                                                                                                                                                                                                           |
| ` E`                                                                           | ` `[peek](https://developer.android.com/reference/java/util/concurrent/DelayQueue#peek())`() ` Retrieves, but does not remove, the[head](https://developer.android.com/reference/java/util/concurrent/DelayQueue#head)of this queue, or returns`null`if this queue is empty.                                                                                                                                                                                                                                                                                                         |
| ` E`                                                                           | ` `[poll](https://developer.android.com/reference/java/util/concurrent/DelayQueue#poll(long,%20java.util.concurrent.TimeUnit))`(long timeout, `[TimeUnit](https://developer.android.com/reference/java/util/concurrent/TimeUnit)` unit) ` Retrieves and removes the[expired head](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired-head)of this queue, waiting if necessary until an[expired element](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired)is available on this queue, or the specified wait time expires. |
| ` E`                                                                           | ` `[poll](https://developer.android.com/reference/java/util/concurrent/DelayQueue#poll())`() ` Retrieves and removes the[expired head](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired-head)of this queue, or returns`null`if this queue has no[expired elements](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired).                                                                                                                                                                                                  |
| ` void`                                                                        | ` `[put](https://developer.android.com/reference/java/util/concurrent/DelayQueue#put(E))`(E e) ` Inserts the specified element into this delay queue.                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` int`                                                                         | ` `[remainingCapacity](https://developer.android.com/reference/java/util/concurrent/DelayQueue#remainingCapacity())`() ` Always returns`Integer.MAX_VALUE`because a`DelayQueue`is not capacity constrained.                                                                                                                                                                                                                                                                                                                                                                          |
| ` E`                                                                           | ` `[remove](https://developer.android.com/reference/java/util/concurrent/DelayQueue#remove())`() ` Retrieves and removes the[expired head](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired-head)of this queue, or throws an exception if this queue has no[expired elements](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired).                                                                                                                                                                                       |
| ` boolean`                                                                     | ` `[remove](https://developer.android.com/reference/java/util/concurrent/DelayQueue#remove(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Removes a single instance of the specified element from this queue, if it is present, whether or not it has expired.                                                                                                                                                                                                                                                                        |
| ` int`                                                                         | ` `[size](https://developer.android.com/reference/java/util/concurrent/DelayQueue#size())`() ` Returns the number of elements in this collection.                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` E`                                                                           | ` `[take](https://developer.android.com/reference/java/util/concurrent/DelayQueue#take())`() ` Retrieves and removes the[expired head](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired-head)of this queue, waiting if necessary until an[expired element](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired)is available on this queue.                                                                                                                                                                                |
| ` <T> T[]`                                                                     | ` `[toArray](https://developer.android.com/reference/java/util/concurrent/DelayQueue#toArray(T[]))`(T[] a) ` Returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array.                                                                                                                                                                                                                                                                                                                                   |
| ` `[Object[]](https://developer.android.com/reference/java/lang/Object)        | ` `[toArray](https://developer.android.com/reference/java/util/concurrent/DelayQueue#toArray())`() ` Returns an array containing all of the elements in this queue.                                                                                                                                                                                                                                                                                                                                                                                                                  |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.util.AbstractQueue](https://developer.android.com/reference/java/util/AbstractQueue)` ` |------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` boolean` | ` `[add](https://developer.android.com/reference/java/util/AbstractQueue#add(E))`(E e) ` Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning`true`upon success and throwing an`IllegalStateException`if no space is currently available. | | ` boolean` | ` `[addAll](https://developer.android.com/reference/java/util/AbstractQueue#addAll(java.util.Collection<?%20extends%20E>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? extends E> c) ` Adds all of the elements in the specified collection to this queue.                               | | ` void`    | ` `[clear](https://developer.android.com/reference/java/util/AbstractQueue#clear())`() ` Removes all of the elements from this queue.                                                                                                                                                                                        | | ` E`       | ` `[element](https://developer.android.com/reference/java/util/AbstractQueue#element())`() ` Retrieves, but does not remove, the head of this queue.                                                                                                                                                                         | | ` E`       | ` `[remove](https://developer.android.com/reference/java/util/AbstractQueue#remove())`() ` Retrieves and removes the head of this queue.                                                                                                                                                                                     | ||
| From class` `[java.util.AbstractCollection](https://developer.android.com/reference/java/util/AbstractCollection)` ` |-----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` boolean`                                                                              | ` `[add](https://developer.android.com/reference/java/util/AbstractCollection#add(E))`(E e) ` Ensures that this collection contains the specified element (optional operation).                                                                                                                                                   | | ` boolean`                                                                              | ` `[addAll](https://developer.android.com/reference/java/util/AbstractCollection#addAll(java.util.Collection<?%20extends%20E>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? extends E> c) ` Adds all of the elements in the specified collection to this collection (optional operation).     | | ` void`                                                                                 | ` `[clear](https://developer.android.com/reference/java/util/AbstractCollection#clear())`() ` Removes all of the elements from this collection (optional operation).                                                                                                                                                              | | ` boolean`                                                                              | ` `[contains](https://developer.android.com/reference/java/util/AbstractCollection#contains(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Returns`true`if this collection contains the specified element.                                                                         | | ` boolean`                                                                              | ` `[containsAll](https://developer.android.com/reference/java/util/AbstractCollection#containsAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> c) ` Returns`true`if this collection contains all of the elements in the specified collection.                       | | ` boolean`                                                                              | ` `[isEmpty](https://developer.android.com/reference/java/util/AbstractCollection#isEmpty())`() ` Returns`true`if this collection contains no elements.                                                                                                                                                                           | | ` abstract `[Iterator](https://developer.android.com/reference/java/util/Iterator)`<E>` | ` `[iterator](https://developer.android.com/reference/java/util/AbstractCollection#iterator())`() ` Returns an iterator over the elements contained in this collection.                                                                                                                                                           | | ` boolean`                                                                              | ` `[remove](https://developer.android.com/reference/java/util/AbstractCollection#remove(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Removes a single instance of the specified element from this collection, if it is present (optional operation).                             | | ` boolean`                                                                              | ` `[removeAll](https://developer.android.com/reference/java/util/AbstractCollection#removeAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> c) ` Removes all of this collection's elements that are also contained in the specified collection (optional operation). | | ` boolean`                                                                              | ` `[retainAll](https://developer.android.com/reference/java/util/AbstractCollection#retainAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> c) ` Retains only the elements in this collection that are contained in the specified collection (optional operation).   | | ` abstract int`                                                                         | ` `[size](https://developer.android.com/reference/java/util/AbstractCollection#size())`() ` Returns the number of elements in this collection.                                                                                                                                                                                    | | ` <T> T[]`                                                                              | ` `[toArray](https://developer.android.com/reference/java/util/AbstractCollection#toArray(T[]))`(T[] a) ` Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.                                                                              | | ` `[Object[]](https://developer.android.com/reference/java/lang/Object)                 | ` `[toArray](https://developer.android.com/reference/java/util/AbstractCollection#toArray())`() ` Returns an array containing all of the elements in this collection.                                                                                                                                                             | | ` `[String](https://developer.android.com/reference/java/lang/String)                   | ` `[toString](https://developer.android.com/reference/java/util/AbstractCollection#toString())`() ` Returns a string representation of this collection.                                                                                                                                                                           | ||
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||
| From interface` `[java.util.Queue](https://developer.android.com/reference/java/util/Queue)` ` |---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract boolean` | ` `[add](https://developer.android.com/reference/java/util/Queue#add(E))`(E e) ` Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning`true`upon success and throwing an`IllegalStateException`if no space is currently available. | | ` abstract E`       | ` `[element](https://developer.android.com/reference/java/util/Queue#element())`() ` Retrieves, but does not remove, the head of this queue.                                                                                                                                                                         | | ` abstract boolean` | ` `[offer](https://developer.android.com/reference/java/util/Queue#offer(E))`(E e) ` Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.                                                                                                   | | ` abstract E`       | ` `[peek](https://developer.android.com/reference/java/util/Queue#peek())`() ` Retrieves, but does not remove, the head of this queue, or returns`null`if this queue is empty.                                                                                                                                       | | ` abstract E`       | ` `[poll](https://developer.android.com/reference/java/util/Queue#poll())`() ` Retrieves and removes the head of this queue, or returns`null`if this queue is empty.                                                                                                                                                 | | ` abstract E`       | ` `[remove](https://developer.android.com/reference/java/util/Queue#remove())`() ` Retrieves and removes the head of this queue.                                                                                                                                                                                     | ||
| From interface` `[java.util.Collection](https://developer.android.com/reference/java/util/Collection)` ` |----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract boolean`                                                                          | ` `[add](https://developer.android.com/reference/java/util/Collection#add(E))`(E e) ` Ensures that this collection contains the specified element (optional operation).                                                                                                                                                                                                      | | ` abstract boolean`                                                                          | ` `[addAll](https://developer.android.com/reference/java/util/Collection#addAll(java.util.Collection<?%20extends%20E>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? extends E> c) ` Adds all of the elements in the specified collection to this collection (optional operation).                                                        | | ` abstract void`                                                                             | ` `[clear](https://developer.android.com/reference/java/util/Collection#clear())`() ` Removes all of the elements from this collection (optional operation).                                                                                                                                                                                                                 | | ` abstract boolean`                                                                          | ` `[contains](https://developer.android.com/reference/java/util/Collection#contains(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Returns`true`if this collection contains the specified element.                                                                                                                            | | ` abstract boolean`                                                                          | ` `[containsAll](https://developer.android.com/reference/java/util/Collection#containsAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> c) ` Returns`true`if this collection contains all of the elements in the specified collection.                                                                          | | ` abstract boolean`                                                                          | ` `[equals](https://developer.android.com/reference/java/util/Collection#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Compares the specified object with this collection for equality.                                                                                                                               | | ` abstract int`                                                                              | ` `[hashCode](https://developer.android.com/reference/java/util/Collection#hashCode())`() ` Returns the hash code value for this collection.                                                                                                                                                                                                                                 | | ` abstract boolean`                                                                          | ` `[isEmpty](https://developer.android.com/reference/java/util/Collection#isEmpty())`() ` Returns`true`if this collection contains no elements.                                                                                                                                                                                                                              | | ` abstract `[Iterator](https://developer.android.com/reference/java/util/Iterator)`<E>`      | ` `[iterator](https://developer.android.com/reference/java/util/Collection#iterator())`() ` Returns an iterator over the elements in this collection.                                                                                                                                                                                                                        | | ` default `[Stream](https://developer.android.com/reference/java/util/stream/Stream)`<E>`    | ` `[parallelStream](https://developer.android.com/reference/java/util/Collection#parallelStream())`() ` Returns a possibly parallel`Stream`with this collection as its source.                                                                                                                                                                                               | | ` abstract boolean`                                                                          | ` `[remove](https://developer.android.com/reference/java/util/Collection#remove(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Removes a single instance of the specified element from this collection, if it is present (optional operation).                                                                                | | ` abstract boolean`                                                                          | ` `[removeAll](https://developer.android.com/reference/java/util/Collection#removeAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> c) ` Removes all of this collection's elements that are also contained in the specified collection (optional operation).                                                    | | ` default boolean`                                                                           | ` `[removeIf](https://developer.android.com/reference/java/util/Collection#removeIf(java.util.function.Predicate<?%20super%20E>))`(`[Predicate](https://developer.android.com/reference/java/util/function/Predicate)`<? super E> filter) ` Removes all of the elements of this collection that satisfy the given predicate.                                                 | | ` abstract boolean`                                                                          | ` `[retainAll](https://developer.android.com/reference/java/util/Collection#retainAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> c) ` Retains only the elements in this collection that are contained in the specified collection (optional operation).                                                      | | ` abstract int`                                                                              | ` `[size](https://developer.android.com/reference/java/util/Collection#size())`() ` Returns the number of elements in this collection.                                                                                                                                                                                                                                       | | ` default `[Spliterator](https://developer.android.com/reference/java/util/Spliterator)`<E>` | ` `[spliterator](https://developer.android.com/reference/java/util/Collection#spliterator())`() ` Creates a[Spliterator](https://developer.android.com/reference/java/util/Spliterator)over the elements in this collection.                                                                                                                                                 | | ` default `[Stream](https://developer.android.com/reference/java/util/stream/Stream)`<E>`    | ` `[stream](https://developer.android.com/reference/java/util/Collection#stream())`() ` Returns a sequential`Stream`with this collection as its source.                                                                                                                                                                                                                      | | ` abstract <T> T[]`                                                                          | ` `[toArray](https://developer.android.com/reference/java/util/Collection#toArray(T[]))`(T[] a) ` Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.                                                                                                                                 | | ` abstract `[Object[]](https://developer.android.com/reference/java/lang/Object)             | ` `[toArray](https://developer.android.com/reference/java/util/Collection#toArray())`() ` Returns an array containing all of the elements in this collection.                                                                                                                                                                                                                | | ` default <T> T[]`                                                                           | ` `[toArray](https://developer.android.com/reference/java/util/Collection#toArray(java.util.function.IntFunction<T[]>))`(`[IntFunction](https://developer.android.com/reference/java/util/function/IntFunction)`<T[]> generator) ` Returns an array containing all of the elements in this collection, using the provided`generator`function to allocate the returned array. | ||
| From interface` `[java.util.concurrent.BlockingQueue](https://developer.android.com/reference/java/util/concurrent/BlockingQueue)` ` |---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract boolean` | ` `[add](https://developer.android.com/reference/java/util/concurrent/BlockingQueue#add(E))`(E e) ` Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning`true`upon success and throwing an`IllegalStateException`if no space is currently available.                                                   | | ` abstract boolean` | ` `[contains](https://developer.android.com/reference/java/util/concurrent/BlockingQueue#contains(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Returns`true`if this queue contains the specified element.                                                                                                                                | | ` abstract int`     | ` `[drainTo](https://developer.android.com/reference/java/util/concurrent/BlockingQueue#drainTo(java.util.Collection<?%20super%20E>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? super E> c) ` Removes all available elements from this queue and adds them to the given collection.                                                                 | | ` abstract int`     | ` `[drainTo](https://developer.android.com/reference/java/util/concurrent/BlockingQueue#drainTo(java.util.Collection<?%20super%20E>,%20int))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? super E> c, int maxElements) ` Removes at most the given number of available elements from this queue and adds them to the given collection.                 | | ` abstract boolean` | ` `[offer](https://developer.android.com/reference/java/util/concurrent/BlockingQueue#offer(E))`(E e) ` Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning`true`upon success and`false`if no space is currently available.                                                                           | | ` abstract boolean` | ` `[offer](https://developer.android.com/reference/java/util/concurrent/BlockingQueue#offer(E,%20long,%20java.util.concurrent.TimeUnit))`(E e, long timeout, `[TimeUnit](https://developer.android.com/reference/java/util/concurrent/TimeUnit)` unit) ` Inserts the specified element into this queue, waiting up to the specified wait time if necessary for space to become available. | | ` abstract E`       | ` `[poll](https://developer.android.com/reference/java/util/concurrent/BlockingQueue#poll(long,%20java.util.concurrent.TimeUnit))`(long timeout, `[TimeUnit](https://developer.android.com/reference/java/util/concurrent/TimeUnit)` unit) ` Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.         | | ` abstract void`    | ` `[put](https://developer.android.com/reference/java/util/concurrent/BlockingQueue#put(E))`(E e) ` Inserts the specified element into this queue, waiting if necessary for space to become available.                                                                                                                                                                                    | | ` abstract int`     | ` `[remainingCapacity](https://developer.android.com/reference/java/util/concurrent/BlockingQueue#remainingCapacity())`() ` Returns the number of additional elements that this queue can ideally (in the absence of memory or resource constraints) accept without blocking, or`Integer.MAX_VALUE`if there is no intrinsic limit.                                                        | | ` abstract boolean` | ` `[remove](https://developer.android.com/reference/java/util/concurrent/BlockingQueue#remove(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Removes a single instance of the specified element from this queue, if it is present.                                                                                                         | | ` abstract E`       | ` `[take](https://developer.android.com/reference/java/util/concurrent/BlockingQueue#take())`() ` Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.                                                                                                                                                                                  | ||
| From interface` `[java.lang.Iterable](https://developer.android.com/reference/java/lang/Iterable)` ` |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` default void`                                                                                                                                                                        | ` `[forEach](https://developer.android.com/reference/java/lang/Iterable#forEach(java.util.function.Consumer<?%20super%20T>))`(`[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<? super T> action) ` Performs the given action for each element of the`Iterable`until all elements have been processed or the action throws an exception. | | ` abstract `[Iterator](https://developer.android.com/reference/java/util/Iterator)`<E extends `[Delayed](https://developer.android.com/reference/java/util/concurrent/Delayed)`>`      | ` `[iterator](https://developer.android.com/reference/java/lang/Iterable#iterator())`() ` Returns an iterator over elements of type`T`.                                                                                                                                                                                                                                   | | ` default `[Spliterator](https://developer.android.com/reference/java/util/Spliterator)`<E extends `[Delayed](https://developer.android.com/reference/java/util/concurrent/Delayed)`>` | ` `[spliterator](https://developer.android.com/reference/java/lang/Iterable#spliterator())`() ` Creates a[Spliterator](https://developer.android.com/reference/java/util/Spliterator)over the elements described by this`Iterable`.                                                                                                                                       | ||

## Public constructors

### DelayQueue

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DelayQueue ()
```

Creates a new`DelayQueue`that is initially empty.

<br />

### DelayQueue

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DelayQueue (Collection<? extends E> c)
```

Creates a`DelayQueue`initially containing the elements of the given collection of[Delayed](https://developer.android.com/reference/java/util/concurrent/Delayed)instances.

<br />

|                                Parameters                                 ||
|-----|----------------------------------------------------------------------|
| `c` | `Collection`: the collection of elements to initially contain <br /> |

|                                                                           Throws                                                                            ||
|------------------------------------------------------------------------------------------------|-------------------------------------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if the specified collection or any of its elements are null |

## Public methods

### add

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean add (E e)
```

Inserts the specified element into this delay queue.

<br />

|             Parameters              ||
|-----|--------------------------------|
| `e` | `E`: the element to add <br /> |

|                                                            Returns                                                             ||
|-----------|---------------------------------------------------------------------------------------------------------------------|
| `boolean` | `true`(as specified by[Collection.add](https://developer.android.com/reference/java/util/Collection#add(E))) <br /> |

|                                                              Throws                                                              ||
|------------------------------------------------------------------------------------------------|----------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if the specified element is null |

### clear

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void clear ()
```

Atomically removes all of the elements from this delay queue. The queue will be empty after this call returns. Elements with an unexpired delay are not waited for; they are simply discarded from the queue.

<br />

### drainTo

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int drainTo (Collection<? super E> c, 
                int maxElements)
```

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.

<br />

|                                  Parameters                                  ||
|---------------|---------------------------------------------------------------|
| `c`           | `Collection`: the collection to transfer elements into <br /> |
| `maxElements` | `int`: the maximum number of elements to transfer <br />      |

|                     Returns                      ||
|-------|-------------------------------------------|
| `int` | the number of elements transferred <br /> |

|                                                       Throws                                                        ||
|------------------------------------------------------------------------------------------------------------------|---|
| [UnsupportedOperationException](https://developer.android.com/reference/java/lang/UnsupportedOperationException) |   |
| [ClassCastException](https://developer.android.com/reference/java/lang/ClassCastException)                       |   |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)                   |   |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException)           |   |

### drainTo

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int drainTo (Collection<? super E> c)
```

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.

<br />

|                             Parameters                             ||
|-----|---------------------------------------------------------------|
| `c` | `Collection`: the collection to transfer elements into <br /> |

|                     Returns                      ||
|-------|-------------------------------------------|
| `int` | the number of elements transferred <br /> |

|                                                       Throws                                                        ||
|------------------------------------------------------------------------------------------------------------------|---|
| [UnsupportedOperationException](https://developer.android.com/reference/java/lang/UnsupportedOperationException) |   |
| [ClassCastException](https://developer.android.com/reference/java/lang/ClassCastException)                       |   |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)                   |   |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException)           |   |

### iterator

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Iterator<E> iterator ()
```

Returns an iterator over all the elements (both expired and unexpired) in this queue. The iterator does not return the elements in any particular order.

The returned iterator is[*weakly consistent*](https://developer.android.com/reference/java/util/concurrent/package-summary#Weakly).

<br />

|                                                             Returns                                                             ||
|-----------------------------------------------------------------------------|----------------------------------------------------|
| [Iterator](https://developer.android.com/reference/java/util/Iterator)`<E>` | an iterator over the elements in this queue <br /> |

### offer

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean offer (E e)
```

Inserts the specified element into this delay queue.

<br />

|             Parameters              ||
|-----|--------------------------------|
| `e` | `E`: the element to add <br /> |

|         Returns          ||
|-----------|---------------|
| `boolean` | `true` <br /> |

|                                                              Throws                                                              ||
|------------------------------------------------------------------------------------------------|----------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if the specified element is null |

### offer

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean offer (E e, 
                long timeout, 
                TimeUnit unit)
```

Inserts the specified element into this delay queue. As the queue is unbounded this method will never block.

<br />

|                                     Parameters                                     ||
|-----------|-------------------------------------------------------------------------|
| `e`       | `E`: the element to add <br />                                          |
| `timeout` | `long`: This parameter is ignored as the method never blocks <br />     |
| `unit`    | `TimeUnit`: This parameter is ignored as the method never blocks <br /> |

|         Returns          ||
|-----------|---------------|
| `boolean` | `true` <br /> |

|                                              Throws                                               ||
|------------------------------------------------------------------------------------------------|---|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) |   |

### peek

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public E peek ()
```

Retrieves, but does not remove, the[head](https://developer.android.com/reference/java/util/concurrent/DelayQueue#head)of this queue, or returns`null`if this queue is empty. Unlike`poll`, if no expired elements are available in the queue, this method returns the element that will expire next, if one exists.

<br />

|                               Returns                               ||
|-----|----------------------------------------------------------------|
| `E` | the*head* of this queue, or`null`if this queue is empty <br /> |

### poll

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public E poll (long timeout, 
                TimeUnit unit)
```

Retrieves and removes the[expired head](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired-head)of this queue, waiting if necessary until an[expired element](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired)is available on this queue, or the specified wait time expires.

<br />

|                                         Parameters                                          ||
|-----------|----------------------------------------------------------------------------------|
| `timeout` | `long`: how long to wait before giving up, in units of`unit` <br />              |
| `unit`    | `TimeUnit`: a`TimeUnit`determining how to interpret the`timeout`parameter <br /> |

|                                                                       Returns                                                                        ||
|-----|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `E` | the*expired head* of this queue, or`null`if the specified waiting time elapses before an element with an expired delay becomes available <br /> |

|                                              Throws                                               ||
|------------------------------------------------------------------------------------------------|---|
| [InterruptedException](https://developer.android.com/reference/java/lang/InterruptedException) |   |

### poll

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public E poll ()
```

Retrieves and removes the[expired head](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired-head)of this queue, or returns`null`if this queue has no[expired elements](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired).

<br />

|                                                 Returns                                                  ||
|-----|-----------------------------------------------------------------------------------------------------|
| `E` | the*expired head* of this queue, or`null`if this queue has no elements with an expired delay <br /> |

### put

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void put (E e)
```

Inserts the specified element into this delay queue. As the queue is unbounded this method will never block.

<br />

|             Parameters              ||
|-----|--------------------------------|
| `e` | `E`: the element to add <br /> |

|                                              Throws                                               ||
|------------------------------------------------------------------------------------------------|---|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) |   |

### remainingCapacity

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int remainingCapacity ()
```

Always returns`Integer.MAX_VALUE`because a`DelayQueue`is not capacity constrained.

<br />

|              Returns              ||
|-------|----------------------------|
| `int` | `Integer.MAX_VALUE` <br /> |

### remove

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public E remove ()
```

Retrieves and removes the[expired head](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired-head)of this queue, or throws an exception if this queue has no[expired elements](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired).

<br />

|                   Returns                   ||
|-----|----------------------------------------|
| `E` | the*expired head* of this queue <br /> |

|                                                                         Throws                                                                          ||
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------|
| [NoSuchElementException](https://developer.android.com/reference/java/util/NoSuchElementException) | if this queue has no elements with an expired delay |

### remove

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean remove (Object o)
```

Removes a single instance of the specified element from this queue, if it is present, whether or not it has expired.

<br />

|                                  Parameters                                  ||
|-----|-------------------------------------------------------------------------|
| `o` | `Object`: element to be removed from this collection, if present <br /> |

|                                  Returns                                   ||
|-----------|-----------------------------------------------------------------|
| `boolean` | `true`if an element was removed as a result of this call <br /> |

### size

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int size ()
```

Returns the number of elements in this collection. If this collection contains more than`Integer.MAX_VALUE`elements, returns`Integer.MAX_VALUE`.

<br />

|                         Returns                         ||
|-------|--------------------------------------------------|
| `int` | the number of elements in this collection <br /> |

### take

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public E take ()
```

Retrieves and removes the[expired head](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired-head)of this queue, waiting if necessary until an[expired element](https://developer.android.com/reference/java/util/concurrent/DelayQueue#expired)is available on this queue.

<br />

|                   Returns                   ||
|-----|----------------------------------------|
| `E` | the*expired head* of this queue <br /> |

|                                              Throws                                               ||
|------------------------------------------------------------------------------------------------|---|
| [InterruptedException](https://developer.android.com/reference/java/lang/InterruptedException) |   |

### toArray

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public T[] toArray (T[] a)
```

Returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array. The returned array elements are in no particular order. If the queue fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this queue.

If this queue fits in the specified array with room to spare (i.e., the array has more elements than this queue), the element in the array immediately following the end of the queue is set to`null`.

Like the[toArray()](https://developer.android.com/reference/java/util/concurrent/DelayQueue#toArray())method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.

The following code can be used to dump a delay queue into a newly allocated array of`Delayed`:  

     Delayed[] a = q.toArray(new Delayed[0]);

Note that`toArray(new Object[0])`is identical in function to`toArray()`.

<br />

<br />

|                                                                                      Parameters                                                                                      ||
|-----|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `a` | `T`: the array into which the elements of the queue are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose <br /> |

|                               Returns                               ||
|-------|--------------------------------------------------------------|
| `T[]` | an array containing all of the elements in this queue <br /> |

|                                                                                                      Throws                                                                                                      ||
|------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
| [ArrayStoreException](https://developer.android.com/reference/java/lang/ArrayStoreException)   | if the runtime type of the specified array is not a supertype of the runtime type of every element in this queue |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if the specified array is null                                                                                   |

### toArray

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Object[] toArray ()
```

Returns an array containing all of the elements in this queue. The returned array elements are in no particular order.

The returned array will be "safe" in that no references to it are maintained by this queue. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

<br />

|                                                              Returns                                                               ||
|----------------------------------------------------------------------|--------------------------------------------------------------|
| [Object[]](https://developer.android.com/reference/java/lang/Object) | an array containing all of the elements in this queue <br /> |