# LongArrayQueue

# LongArrayQueue

Artifact:[androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3)  
[View Source](https://cs.android.com/search?q=file:androidx/media3/common/util/LongArrayQueue.java+class:androidx.media3.common.util.LongArrayQueue)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/common/util/LongArrayQueue "View this page in Java")

<br />

```
@UnstableApi
class LongArrayQueue
```

<br />

*** ** * ** ***

Array-based unbounded queue for long primitives with amortized O(1) add and remove.

Use this class instead of a[java.util.Deque](https://developer.android.com/reference/java/util/Deque.html)to avoid boxing long primitives to[Long](https://developer.android.com/reference/java/lang/Long.html)instances.

## Summary

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [DEFAULT_INITIAL_CAPACITY](https://developer.android.com/reference/kotlin/androidx/media3/common/util/LongArrayQueue#DEFAULT_INITIAL_CAPACITY())` = 16` Default initial capacity. |

|                                                                                                                                                    ### Public constructors                                                                                                                                                    |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [LongArrayQueue](https://developer.android.com/reference/kotlin/androidx/media3/common/util/LongArrayQueue#LongArrayQueue())`()` Creates a queue with an initial capacity of[DEFAULT_INITIAL_CAPACITY](https://developer.android.com/reference/kotlin/androidx/media3/common/util/LongArrayQueue#DEFAULT_INITIAL_CAPACITY()). |
| [LongArrayQueue](https://developer.android.com/reference/kotlin/androidx/media3/common/util/LongArrayQueue#LongArrayQueue(int))`(minCapacity: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Creates a queue with capacity for at least`minCapacity`                                         |

|                                ### Public functions                                 |
|-------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [add](https://developer.android.com/reference/kotlin/androidx/media3/common/util/LongArrayQueue#add(long))`(value: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Add a new item to the queue. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [clear](https://developer.android.com/reference/kotlin/androidx/media3/common/util/LongArrayQueue#clear())`()` Clears the queue.                                                                                                  |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)       | [element](https://developer.android.com/reference/kotlin/androidx/media3/common/util/LongArrayQueue#element())`()` Retrieves, but does not remove, the head of the queue.                                                         |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [isEmpty](https://developer.android.com/reference/kotlin/androidx/media3/common/util/LongArrayQueue#isEmpty())`()` Returns whether the queue is empty.                                                                            |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)       | [remove](https://developer.android.com/reference/kotlin/androidx/media3/common/util/LongArrayQueue#remove())`()` Remove an item from the queue.                                                                                   |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)         | [size](https://developer.android.com/reference/kotlin/androidx/media3/common/util/LongArrayQueue#size())`()` Returns the number of items in the queue.                                                                            |

## Constants

### DEFAULT_INITIAL_CAPACITY

```
const val DEFAULT_INITIAL_CAPACITY = 16: Int
```

Default initial capacity.  

## Public constructors

### LongArrayQueue

```
LongArrayQueue()
```

Creates a queue with an initial capacity of[DEFAULT_INITIAL_CAPACITY](https://developer.android.com/reference/kotlin/androidx/media3/common/util/LongArrayQueue#DEFAULT_INITIAL_CAPACITY()).  

### LongArrayQueue

```
LongArrayQueue(minCapacity: Int)
```

Creates a queue with capacity for at least`minCapacity`  

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| `minCapacity: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | minCapacity the minimum capacity, between 1 and 2\^30 inclusive |

## Public functions

### add

```
fun add(value: Long): Unit
```

Add a new item to the queue.  

### clear

```
fun clear(): Unit
```

Clears the queue.  

### element

```
fun element(): Long
```

Retrieves, but does not remove, the head of the queue.  

|                                                      Throws                                                       |
|-------------------------------------------------------------------------------------------------------------------|------------------------|
| [java.util.NoSuchElementException](https://developer.android.com/reference/java/util/NoSuchElementException.html) | if the queue is empty. |

### isEmpty

```
fun isEmpty(): Boolean
```

Returns whether the queue is empty.  

### remove

```
fun remove(): Long
```

Remove an item from the queue.  

|                                                      Throws                                                       |
|-------------------------------------------------------------------------------------------------------------------|------------------------|
| [java.util.NoSuchElementException](https://developer.android.com/reference/java/util/NoSuchElementException.html) | if the queue is empty. |

### size

```
fun size(): Int
```

Returns the number of items in the queue.