# IntSet

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

*** ** * ** ***


```
public sealed class IntSet
```

<br />

Known direct subclasses [MutableIntSet](https://developer.android.com/reference/androidx/collection/MutableIntSet)

|---|---|
| `https://developer.android.com/reference/androidx/collection/MutableIntSet` | `https://developer.android.com/reference/androidx/collection/MutableIntSet` 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. |

*** ** * ** ***

`https://developer.android.com/reference/androidx/collection/IntSet` is a container with a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html`-like interface designed to avoid allocations, including boxing.

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

Though `https://developer.android.com/reference/androidx/collection/IntSet` offers a read-only interface, it is always backed by a `https://developer.android.com/reference/androidx/collection/MutableIntSet`. Read operations alone are thread-safe. However, any mutations done through the backing `https://developer.android.com/reference/androidx/collection/MutableIntSet` while reading on another thread are not safe and the developer must protect the set from such changes during read operations.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/collection/MutableIntSet` |   |

## Summary

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/androidx/collection/IntSet#IntSet()()` |

| ### Public methods |
|---|---|
| `final boolean` | `https://developer.android.com/reference/androidx/collection/IntSet#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/Integer.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/IntSet#all(kotlin.Function1)`. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/IntSet#any()()` Returns `true` if this set has at least one element. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/IntSet#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/Integer.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/IntSet#any(kotlin.Function1)`. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/IntSet#contains(kotlin.Int)(int element)` Returns `true` if the specified `https://developer.android.com/reference/androidx/collection/IntSet#contains(kotlin.Int)` 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/IntSet#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/IntSet#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/Integer.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/IntSet#count(kotlin.Function1)`. |
| `boolean` | `https://developer.android.com/reference/androidx/collection/IntSet#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` Compares the specified object `https://developer.android.com/reference/androidx/collection/IntSet#equals(kotlin.Any)` with this set for equality. |
| `final int` | `https://developer.android.com/reference/androidx/collection/IntSet#first()()` Returns the first element in the collection. |
| `final int` | `https://developer.android.com/reference/androidx/collection/IntSet#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/Integer.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/IntSet#first(kotlin.Function1)` returns `true`. |
| `final void` | `https://developer.android.com/reference/androidx/collection/IntSet#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/Integer.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/IntSet#forEach(kotlin.Function1)` lambda. |
| `final @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` | `https://developer.android.com/reference/androidx/collection/IntSet#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/IntSet#getSize()()` Returns the number of elements in this set. |
| `int` | `https://developer.android.com/reference/androidx/collection/IntSet#hashCode()()` Returns the hash code value for this set. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/IntSet#isEmpty()()` Indicates whether this set is empty. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/IntSet#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/IntSet#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/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)` and using `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)` before and `https://developer.android.com/reference/androidx/collection/IntSet#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/IntSet#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/Integer.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/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)` and using `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)` before and `https://developer.android.com/reference/androidx/collection/IntSet#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/IntSet#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/IntSet#toString()()` Returns a string representation of this set. |

## Protected constructors

### IntSet

```
protected IntSet()
```

## Public methods

### all

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

```
public final boolean all(@NonNull Function1<@NonNull Integer, @NonNull Boolean> predicate)
```

Returns true if all elements match the given `https://developer.android.com/reference/androidx/collection/IntSet#all(kotlin.Function1)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate` | called for elements in the set to determine if it returns return `true` for all elements. |

### any

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

```
public final boolean any()
```

Returns `true` if this set has at least one element.

### any

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

```
public final boolean any(@NonNull Function1<@NonNull Integer, @NonNull Boolean> predicate)
```

Returns true if at least one element matches the given `https://developer.android.com/reference/androidx/collection/IntSet#any(kotlin.Function1)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate` | called for elements in the set to determine if it returns `true` for any elements. |

### contains

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

```
public final boolean contains(int element)
```

Returns `true` if the specified `https://developer.android.com/reference/androidx/collection/IntSet#contains(kotlin.Int)` is present in this set, `false` otherwise.

| Parameters |
|---|---|
| `int element` | The element to look for in this set |

### count

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

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

Returns the number of elements in this set.

### count

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

```
public final @IntRange(from = 0) int count(@NonNull Function1<@NonNull Integer, @NonNull Boolean> predicate)
```

Returns the number of elements matching the given `https://developer.android.com/reference/androidx/collection/IntSet#count(kotlin.Function1)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate` | Called for all elements in the set to count the number for which it returns `true`. |

### equals

```
public boolean equals(Object other)
```

Compares the specified object `https://developer.android.com/reference/androidx/collection/IntSet#equals(kotlin.Any)` with this set for equality. The two objects are considered equal if `https://developer.android.com/reference/androidx/collection/IntSet#equals(kotlin.Any)`:

- Is a `https://developer.android.com/reference/androidx/collection/IntSet`

- Has the same `https://developer.android.com/reference/androidx/collection/IntSet#size()` as this set

- Contains elements equal to this set's elements

### first

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

```
public final int first()
```

Returns the first element in the collection.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-no-such-element-exception/index.html` | if the collection is empty |

### first

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

```
public final int first(@NonNull Function1<@NonNull Integer, @NonNull Boolean> predicate)
```

Returns the first element in the collection for which `https://developer.android.com/reference/androidx/collection/IntSet#first(kotlin.Function1)` returns `true`.

**Note** There is no mechanism for both determining if there is an element that matches `https://developer.android.com/reference/androidx/collection/IntSet#first(kotlin.Function1)` *and* returning it if it exists. Developers should use `https://developer.android.com/reference/androidx/collection/IntSet#forEach(kotlin.Function1)` to achieve this behavior.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate` | Called on elements of the set, returning `true` for an element that matches or `false` if it doesn't |

| Returns |
|---|---|
| `int` | An element in the set for which `https://developer.android.com/reference/androidx/collection/IntSet#first(kotlin.Function1)` returns `true`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-no-such-element-exception/index.html` | if `https://developer.android.com/reference/androidx/collection/IntSet#first(kotlin.Function1)` returns `false` for all elements or the collection is empty. |

### forEach

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

```
public final void forEach(@NonNull Function1<@NonNull Integer, Unit> block)
```

Iterates over every element stored in this set by invoking the specified `https://developer.android.com/reference/androidx/collection/IntSet#forEach(kotlin.Function1)` lambda.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> block` | called with each element in the set |

### getCapacity

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

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

Returns the number of elements that can be stored in this set without requiring internal storage reallocation.

### getSize

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

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

Returns the number of elements in this set.

### hashCode

```
public int hashCode()
```

Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set.

### isEmpty

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

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

Indicates whether this set is empty.

### isNotEmpty

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

```
public final boolean isNotEmpty()
```

Returns `true` if this set is not empty.

### joinToString

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

```
public final @NonNull String joinToString(
    @NonNull CharSequence separator,
    @NonNull CharSequence prefix,
    @NonNull CharSequence postfix,
    int limit,
    @NonNull CharSequence truncated
)
```

Creates a String from the elements separated by `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)` and using `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)` before and `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)` after, if supplied.

When a non-negative value of `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)` is provided, a maximum of `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)` items are used to generate the string. If the collection holds more than `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)` items, the string is terminated with `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence)`.

### joinToString

```
public final @NonNull String joinToString(
    @NonNull CharSequence separator,
    @NonNull CharSequence prefix,
    @NonNull CharSequence postfix,
    int limit,
    @NonNull CharSequence truncated,
    @NonNull Function1<@NonNull Integer, @NonNull CharSequence> transform
)
```

Creates a String from the elements separated by `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)` and using `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)` before and `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)` after, if supplied. `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)` dictates how each element will be represented.

When a non-negative value of `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)` is provided, a maximum of `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)` items are used to generate the string. If the collection holds more than `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)` items, the string is terminated with `https://developer.android.com/reference/androidx/collection/IntSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)`.

### none

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

```
public final boolean none()
```

Returns `true` if this set has no elements.

### toString

```
public @NonNull String toString()
```

Returns a string representation of this set. The set is denoted in the string by the `{}`. Each element is separated by `, `.