# 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)

*** ** * ** ***


```
@UnstableApi
public final class LongArrayQueue
```

<br />

*** ** * ** ***

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

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

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/util/LongArrayQueue#DEFAULT_INITIAL_CAPACITY() = 16` Default initial capacity. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/common/util/LongArrayQueue#LongArrayQueue()()` Creates a queue with an initial capacity of `https://developer.android.com/reference/androidx/media3/common/util/LongArrayQueue#DEFAULT_INITIAL_CAPACITY()`. |
| `https://developer.android.com/reference/androidx/media3/common/util/LongArrayQueue#LongArrayQueue(int)(int minCapacity)` Creates a queue with capacity for at least `minCapacity` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/LongArrayQueue#add(long)(long value)` Add a new item to the queue. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/LongArrayQueue#clear()()` Clears the queue. |
| `long` | `https://developer.android.com/reference/androidx/media3/common/util/LongArrayQueue#element()()` Retrieves, but does not remove, the head of the queue. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/util/LongArrayQueue#isEmpty()()` Returns whether the queue is empty. |
| `long` | `https://developer.android.com/reference/androidx/media3/common/util/LongArrayQueue#remove()()` Remove an item from the queue. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/LongArrayQueue#size()()` Returns the number of items in the queue. |

## Constants

### DEFAULT_INITIAL_CAPACITY

```
public static final int DEFAULT_INITIAL_CAPACITY = 16
```

Default initial capacity.

## Public constructors

### LongArrayQueue

```
public LongArrayQueue()
```

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

### LongArrayQueue

```
public LongArrayQueue(int minCapacity)
```

Creates a queue with capacity for at least `minCapacity`

| Parameters |
|---|---|
| `int minCapacity` | minCapacity the minimum capacity, between 1 and 2\^30 inclusive |

## Public methods

### add

```
public void add(long value)
```

Add a new item to the queue.

### clear

```
public void clear()
```

Clears the queue.

### element

```
public long element()
```

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

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

### isEmpty

```
public boolean isEmpty()
```

Returns whether the queue is empty.

### remove

```
public long remove()
```

Remove an item from the queue.

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

### size

```
public int size()
```

Returns the number of items in the queue.