# MutableLongSet

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

*** ** * ** ***


```
public final class MutableLongSet extends LongSet
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.collection.LongSet](https://developer.android.com/reference/androidx/collection/LongSet) ||
|   | ↳ | [androidx.collection.MutableLongSet](https://developer.android.com/reference/androidx/collection/MutableLongSet) |

*** ** * ** ***

`https://developer.android.com/reference/androidx/collection/MutableLongSet` is a container with a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html`-like interface based on a flat hash table implementation. The underlying implementation is designed to avoid all allocations on insertion, removal, retrieval, and iteration. Allocations may still happen on insertion when the underlying storage needs to grow to accommodate newly added elements to the set.

This implementation makes no guarantee as to the order of the elements stored, nor does it make guarantees that the order remains constant over time.

This implementation is not thread-safe: if multiple threads access this container concurrently, and one or more threads modify the structure of the set (insertion or removal for instance), the calling code must provide the appropriate synchronization. Concurrent reads are however safe.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/collection/MutableLongSet#MutableLongSet(kotlin.Int)(int initialCapacity)` Creates a new `https://developer.android.com/reference/androidx/collection/MutableLongSet` |

| ### Public methods |
|---|---|
| `final boolean` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#add(kotlin.Long)(long element)` Adds the specified element to the set. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#addAll(kotlin.LongArray)(@https://developer.android.com/reference/androidx/annotation/NonNull long[] elements)` Adds all the `https://developer.android.com/reference/androidx/collection/MutableLongSet#addAll(kotlin.LongArray)` into this set. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#addAll(androidx.collection.LongSet)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/LongSet elements)` Adds all the elements in the `https://developer.android.com/reference/androidx/collection/MutableLongSet#addAll(androidx.collection.LongSet)` set into this set. |
| `final void` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#clear()()` Removes all elements from this set. |
| `final void` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#minusAssign(kotlin.Long)(long element)` Removes the specified `https://developer.android.com/reference/androidx/collection/MutableLongSet#minusAssign(kotlin.Long)` from the set if it is present. |
| `final void` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#minusAssign(kotlin.LongArray)(@https://developer.android.com/reference/androidx/annotation/NonNull long[] elements)` Removes the specified `https://developer.android.com/reference/androidx/collection/MutableLongSet#minusAssign(kotlin.LongArray)` from the set, if present. |
| `final void` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#minusAssign(androidx.collection.LongSet)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/LongSet elements)` Removes the specified `https://developer.android.com/reference/androidx/collection/MutableLongSet#minusAssign(androidx.collection.LongSet)` from the set, if present. |
| `final void` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#plusAssign(kotlin.Long)(long element)` Adds the specified element to the set. |
| `final void` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#plusAssign(kotlin.LongArray)(@https://developer.android.com/reference/androidx/annotation/NonNull long[] elements)` Adds all the `https://developer.android.com/reference/androidx/collection/MutableLongSet#plusAssign(kotlin.LongArray)` into this set. |
| `final void` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#plusAssign(androidx.collection.LongSet)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/LongSet elements)` Adds all the elements in the `https://developer.android.com/reference/androidx/collection/MutableLongSet#plusAssign(androidx.collection.LongSet)` set into this set. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#remove(kotlin.Long)(long element)` Removes the specified `https://developer.android.com/reference/androidx/collection/MutableLongSet#remove(kotlin.Long)` from the set. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#removeAll(kotlin.LongArray)(@https://developer.android.com/reference/androidx/annotation/NonNull long[] elements)` Removes the specified `https://developer.android.com/reference/androidx/collection/MutableLongSet#removeAll(kotlin.LongArray)` from the set, if present. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#removeAll(androidx.collection.LongSet)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/LongSet elements)` Removes the specified `https://developer.android.com/reference/androidx/collection/MutableLongSet#removeAll(androidx.collection.LongSet)` from the set, if present. |
| `final @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` | `https://developer.android.com/reference/androidx/collection/MutableLongSet#trim()()` Trims this `https://developer.android.com/reference/androidx/collection/MutableLongSet`'s storage so it is sized appropriately to hold the current elements. |

| ### Inherited methods |
|---|
| From [androidx.collection.LongSet](https://developer.android.com/reference/androidx/collection/LongSet) |---|---| | `final boolean` | `https://developer.android.com/reference/androidx/collection/LongSet#all(kotlin.Function1)(@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Long.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate)` Returns true if all elements match the given `https://developer.android.com/reference/androidx/collection/LongSet#all(kotlin.Function1)`. | | `final boolean` | `https://developer.android.com/reference/androidx/collection/LongSet#any()()` Returns `true` if this set has at least one element. | | `final boolean` | `https://developer.android.com/reference/androidx/collection/LongSet#any(kotlin.Function1)(@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Long.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate)` Returns true if at least one element matches the given `https://developer.android.com/reference/androidx/collection/LongSet#any(kotlin.Function1)`. | | `final boolean` | `https://developer.android.com/reference/androidx/collection/LongSet#contains(kotlin.Long)(long element)` Returns `true` if the specified `https://developer.android.com/reference/androidx/collection/LongSet#contains(kotlin.Long)` is present in this set, `false` otherwise. | | `final @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` | `https://developer.android.com/reference/androidx/collection/LongSet#count()()` Returns the number of elements in this set. | | `final @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` | `https://developer.android.com/reference/androidx/collection/LongSet#count(kotlin.Function1)(@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Long.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate)` Returns the number of elements matching the given `https://developer.android.com/reference/androidx/collection/LongSet#count(kotlin.Function1)`. | | `boolean` | `https://developer.android.com/reference/androidx/collection/LongSet#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` Compares the specified object `https://developer.android.com/reference/androidx/collection/LongSet#equals(kotlin.Any)` with this set for equality. | | `final long` | `https://developer.android.com/reference/androidx/collection/LongSet#first()()` Returns the first element in the collection. | | `final long` | `https://developer.android.com/reference/androidx/collection/LongSet#first(kotlin.Function1)(@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Long.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate)` Returns the first element in the collection for which `https://developer.android.com/reference/androidx/collection/LongSet#first(kotlin.Function1)` returns `true`. | | `final void` | `https://developer.android.com/reference/androidx/collection/LongSet#forEach(kotlin.Function1)(@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Long.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> block)` Iterates over every element stored in this set by invoking the specified `https://developer.android.com/reference/androidx/collection/LongSet#forEach(kotlin.Function1)` lambda. | | `final @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` | `https://developer.android.com/reference/androidx/collection/LongSet#getCapacity()()` Returns the number of elements that can be stored in this set without requiring internal storage reallocation. | | `final @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` | `https://developer.android.com/reference/androidx/collection/LongSet#getSize()()` Returns the number of elements in this set. | | `int` | `https://developer.android.com/reference/androidx/collection/LongSet#hashCode()()` Returns the hash code value for this set. | | `final boolean` | `https://developer.android.com/reference/androidx/collection/LongSet#isEmpty()()` Indicates whether this set is empty. | | `final boolean` | `https://developer.android.com/reference/androidx/collection/LongSet#isNotEmpty()()` Returns `true` if this set is not empty. | | `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/collection/LongSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html separator, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html prefix, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html postfix, int limit, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html truncated )` Creates a String from the elements separated by `https://developer.android.com/reference/androidx/collection/LongSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)` and using `https://developer.android.com/reference/androidx/collection/LongSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)` before and `https://developer.android.com/reference/androidx/collection/LongSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)` after, if supplied. | | `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/collection/LongSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html separator, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html prefix, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html postfix, int limit, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html truncated, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Long.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html> transform )` Creates a String from the elements separated by `https://developer.android.com/reference/androidx/collection/LongSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)` and using `https://developer.android.com/reference/androidx/collection/LongSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)` before and `https://developer.android.com/reference/androidx/collection/LongSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)` after, if supplied. | | `final boolean` | `https://developer.android.com/reference/androidx/collection/LongSet#none()()` Returns `true` if this set has no elements. | | `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/collection/LongSet#toString()()` Returns a string representation of this set. | |

## Public constructors

### MutableLongSet

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

```
public MutableLongSet(int initialCapacity)
```

Creates a new `https://developer.android.com/reference/androidx/collection/MutableLongSet`

| Parameters |
|---|---|
| `int initialCapacity` | The initial desired capacity for this container. The container will honor this value by guaranteeing its internal structures can hold that many elements without requiring any allocations. The initial capacity can be set to 0. |

## Public methods

### add

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

```
public final boolean add(long element)
```

Adds the specified element to the set.

| Parameters |
|---|---|
| `long element` | The element to add to the set. |

| Returns |
|---|---|
| `boolean` | `true` if the element has been added or `false` if the element is already contained within the set. |

### addAll

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

```
public final boolean addAll(@NonNull long[] elements)
```

Adds all the `https://developer.android.com/reference/androidx/collection/MutableLongSet#addAll(kotlin.LongArray)` into this set.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull long[] elements` | An array of elements to add to the set. |

| Returns |
|---|---|
| `boolean` | `true` if any of the specified elements were added to the collection, `false` if the collection was not modified. |

### addAll

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

```
public final boolean addAll(@NonNull LongSet elements)
```

Adds all the elements in the `https://developer.android.com/reference/androidx/collection/MutableLongSet#addAll(androidx.collection.LongSet)` set into this set.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/LongSet elements` | A `https://developer.android.com/reference/androidx/collection/LongSet` of elements to add to this set. |

| Returns |
|---|---|
| `boolean` | `true` if any of the specified elements were added to the collection, `false` if the collection was not modified. |

### clear

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

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

Removes all elements from this set.

### minusAssign

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

```
public final void minusAssign(long element)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/MutableLongSet#minusAssign(kotlin.Long)` from the set if it is present.

| Parameters |
|---|---|
| `long element` | The element to remove from the set. |

### minusAssign

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

```
public final void minusAssign(@NonNull long[] elements)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/MutableLongSet#minusAssign(kotlin.LongArray)` from the set, if present.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull long[] elements` | An array of elements to be removed from the set. |

### minusAssign

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

```
public final void minusAssign(@NonNull LongSet elements)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/MutableLongSet#minusAssign(androidx.collection.LongSet)` from the set, if present.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/LongSet elements` | An `https://developer.android.com/reference/androidx/collection/LongSet` of elements to be removed from the set. |

### plusAssign

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

```
public final void plusAssign(long element)
```

Adds the specified element to the set.

| Parameters |
|---|---|
| `long element` | The element to add to the set. |

### plusAssign

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

```
public final void plusAssign(@NonNull long[] elements)
```

Adds all the `https://developer.android.com/reference/androidx/collection/MutableLongSet#plusAssign(kotlin.LongArray)` into this set.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull long[] elements` | An array of elements to add to the set. |

### plusAssign

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

```
public final void plusAssign(@NonNull LongSet elements)
```

Adds all the elements in the `https://developer.android.com/reference/androidx/collection/MutableLongSet#plusAssign(androidx.collection.LongSet)` set into this set.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/LongSet elements` | A `https://developer.android.com/reference/androidx/collection/LongSet` of elements to add to this set. |

### remove

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

```
public final boolean remove(long element)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/MutableLongSet#remove(kotlin.Long)` from the set.

| Parameters |
|---|---|
| `long element` | The element to remove from the set. |

| Returns |
|---|---|
| `boolean` | `true` if the `https://developer.android.com/reference/androidx/collection/MutableLongSet#remove(kotlin.Long)` was present in the set, or `false` if it wasn't present before removal. |

### removeAll

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

```
public final boolean removeAll(@NonNull long[] elements)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/MutableLongSet#removeAll(kotlin.LongArray)` from the set, if present.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull long[] elements` | An array of elements to be removed from the set. |

| Returns |
|---|---|
| `boolean` | `true` if the set was changed or `false` if none of the elements were present. |

### removeAll

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

```
public final boolean removeAll(@NonNull LongSet elements)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/MutableLongSet#removeAll(androidx.collection.LongSet)` from the set, if present.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/LongSet elements` | An `https://developer.android.com/reference/androidx/collection/LongSet` of elements to be removed from the set. |

| Returns |
|---|---|
| `boolean` | `true` if the set was changed or `false` if none of the elements were present. |

### trim

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

```
public final @IntRange(from = 0) int trim()
```

Trims this `https://developer.android.com/reference/androidx/collection/MutableLongSet`'s storage so it is sized appropriately to hold the current elements.

Returns the number of empty elements removed from this set's storage. Returns 0 if no trimming is necessary or possible.