# CircularIntArray

Artifact: [androidx.collection:collection](https://developer.android.com/jetpack/androidx/releases/collection) [View Source](https://cs.android.com/search?q=file:androidx/collection/CircularIntArray.kt+class:androidx.collection.CircularIntArray) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

*** ** * ** ***


```
public final class CircularIntArray
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/androidx/collection/CircularIntArray` is a circular integer array data structure that provides O(1) random read, O(1) prepend and O(1) append. The CircularIntArray automatically grows its capacity when number of added integers is over its capacity.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/collection/CircularIntArray#CircularIntArray(kotlin.Int)(int minCapacity)` Creates a circular array with capacity for at least `https://developer.android.com/reference/androidx/collection/CircularIntArray#(kotlin.Int)` elements. |

| ### Public methods |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/collection/CircularIntArray#addFirst(kotlin.Int)(int element)` Add an integer in front of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`. |
| `final void` | `https://developer.android.com/reference/androidx/collection/CircularIntArray#addLast(kotlin.Int)(int element)` Add an integer at end of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`. |
| `final void` | `https://developer.android.com/reference/androidx/collection/CircularIntArray#clear()()` Remove all integers from the `https://developer.android.com/reference/androidx/collection/CircularIntArray`. |
| `final int` | `https://developer.android.com/reference/androidx/collection/CircularIntArray#get(kotlin.Int)(int index)` Get nth (0 \<= n \<= size()-1) integer of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`. |
| `final int` | `https://developer.android.com/reference/androidx/collection/CircularIntArray#getFirst()()` Get first integer of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`. |
| `final int` | `https://developer.android.com/reference/androidx/collection/CircularIntArray#getLast()()` Get last integer of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/CircularIntArray#isEmpty()()` Return `true` if `https://developer.android.com/reference/androidx/collection/CircularIntArray#size()` is 0. |
| `final int` | `https://developer.android.com/reference/androidx/collection/CircularIntArray#popFirst()()` Remove first integer from front of the `https://developer.android.com/reference/androidx/collection/CircularIntArray` and return it. |
| `final int` | `https://developer.android.com/reference/androidx/collection/CircularIntArray#popLast()()` Remove last integer from end of the `https://developer.android.com/reference/androidx/collection/CircularIntArray` and return it. |
| `final void` | `https://developer.android.com/reference/androidx/collection/CircularIntArray#removeFromEnd(kotlin.Int)(int count)` Remove multiple elements from end of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`, ignore when `https://developer.android.com/reference/androidx/collection/CircularIntArray#removeFromEnd(kotlin.Int)` is less than or equals to 0. |
| `final void` | `https://developer.android.com/reference/androidx/collection/CircularIntArray#removeFromStart(kotlin.Int)(int count)` Remove multiple integers from front of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`, ignore when `https://developer.android.com/reference/androidx/collection/CircularIntArray#removeFromStart(kotlin.Int)` is less than or equals to 0. |
| `final int` | `https://developer.android.com/reference/androidx/collection/CircularIntArray#size()()` Get number of integers in the `https://developer.android.com/reference/androidx/collection/CircularIntArray`. |

## Public constructors

### CircularIntArray

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public CircularIntArray(int minCapacity)
```

Creates a circular array with capacity for at least `https://developer.android.com/reference/androidx/collection/CircularIntArray#(kotlin.Int)` elements.

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

## Public methods

### addFirst

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public final void addFirst(int element)
```

Add an integer in front of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`.

| Parameters |
|---|---|
| `int element` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` to add. |

### addLast

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public final void addLast(int element)
```

Add an integer at end of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`.

| Parameters |
|---|---|
| `int element` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` to add. |

### clear

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public final void clear()
```

Remove all integers from the `https://developer.android.com/reference/androidx/collection/CircularIntArray`.

### get

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public final int get(int index)
```

Get nth (0 \<= n \<= size()-1) integer of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`.

| Parameters |
|---|---|
| `int index` | The zero based element index in the `https://developer.android.com/reference/androidx/collection/CircularIntArray`. |

| Returns |
|---|---|
| `int` | The nth integer. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if n \< 0 or n \>= size(). |

### getFirst

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public final int getFirst()
```

Get first integer of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`.

| Returns |
|---|---|
| `int` | The first integer. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if `https://developer.android.com/reference/androidx/collection/CircularIntArray` is empty. |

### getLast

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public final int getLast()
```

Get last integer of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`.

| Returns |
|---|---|
| `int` | The last integer. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if `https://developer.android.com/reference/androidx/collection/CircularIntArray` is empty. |

### isEmpty

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public final boolean isEmpty()
```

Return `true` if `https://developer.android.com/reference/androidx/collection/CircularIntArray#size()` is 0.

| Returns |
|---|---|
| `boolean` | `true` if `https://developer.android.com/reference/androidx/collection/CircularIntArray#size()` is 0. |

### popFirst

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public final int popFirst()
```

Remove first integer from front of the `https://developer.android.com/reference/androidx/collection/CircularIntArray` and return it.

| Returns |
|---|---|
| `int` | The integer removed. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if `https://developer.android.com/reference/androidx/collection/CircularIntArray` is empty. |

### popLast

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public final int popLast()
```

Remove last integer from end of the `https://developer.android.com/reference/androidx/collection/CircularIntArray` and return it.

| Returns |
|---|---|
| `int` | The integer removed. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if `https://developer.android.com/reference/androidx/collection/CircularIntArray` is empty. |

### removeFromEnd

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public final void removeFromEnd(int count)
```

Remove multiple elements from end of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`, ignore when `https://developer.android.com/reference/androidx/collection/CircularIntArray#removeFromEnd(kotlin.Int)` is less than or equals to 0.

| Parameters |
|---|---|
| `int count` | Number of integers to remove. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if `https://developer.android.com/reference/androidx/collection/CircularIntArray#removeFromEnd(kotlin.Int)` is larger than `https://developer.android.com/reference/androidx/collection/CircularIntArray#size()` |

### removeFromStart

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public final void removeFromStart(int count)
```

Remove multiple integers from front of the `https://developer.android.com/reference/androidx/collection/CircularIntArray`, ignore when `https://developer.android.com/reference/androidx/collection/CircularIntArray#removeFromStart(kotlin.Int)` is less than or equals to 0.

| Parameters |
|---|---|
| `int count` | Number of integers to remove. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if numOfElements is larger than `https://developer.android.com/reference/androidx/collection/CircularIntArray#size()` |

### size

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/collection#1.0.0)

```
public final int size()
```

Get number of integers in the `https://developer.android.com/reference/androidx/collection/CircularIntArray`.

| Returns |
|---|---|
| `int` | Number of integers in the `https://developer.android.com/reference/androidx/collection/CircularIntArray`. |