# Selection

Artifact: [androidx.recyclerview:recyclerview-selection](https://developer.android.com/jetpack/androidx/releases/recyclerview) [View Source](https://cs.android.com/search?q=file:androidx/recyclerview/selection/Selection.java+class:androidx.recyclerview.selection.Selection) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

*** ** * ** ***


```
class Selection<K> : (Mutable)Iterable<K!>
```

<br />

Known direct subclasses [MutableSelection](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/MutableSelection)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/MutableSelection` | Subclass of `https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection` exposing public support for mutating the underlying selection data. |

*** ** * ** ***

Object representing a "primary" selection and a "provisional" selection.

This class tracks selected items by managing two sets:

**Primary Selection**

Primary selection consists of items selected by a user. This represents the selection "at rest", as the selection does not contains items that are in a "provisional" selected state created by way of an ongoing gesture or band operation.

**Provisional Selection**

Provisional selections are selections which are interim in nature.

Provisional selection exists to address issues where a transitory selection might momentarily intersect with a previously established selection resulting in a some or all of the established selection being erased. Such situations may arise when band selection is being performed in "additive" mode (e.g. SHIFT or CTRL is pressed on the keyboard prior to mouse down), or when there's an active gesture selection (which can be initiated by long pressing an unselected item while there is an existing selection).

| Parameters |
|---|---|
| `<K>` | Selection key type. @see `https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/StorageStrategy` for supported types. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/MutableSelection` |   |

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection#contains(K)(key: K?)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection#equals(java.lang.Object)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection#hashCode()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection#isEmpty()()` |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-iterator/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterator/index.html<K!>` | `https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection#iterator()()` Returns an `https://developer.android.com/reference/java/util/Iterator.html` that iterators over the selection, \*excluding\* any provisional selection. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection#size()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/Selection#toString()()` |

### Inherited functions

From [java.lang.Iterable](https://developer.android.com/reference/java/lang/Iterable.html) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/for-each.html(action: https://developer.android.com/reference/java/util/function/Consumer.html<T!>!)` `https://developer.android.com/reference/java/util/Spliterator.html<T!>!` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/spliterator.html()`

## Public functions

### contains

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

```
fun contains(key: K?): Boolean
```

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the position is currently selected. |

### equals

```
fun equals(other: Any!): Boolean
```

### hashCode

```
fun hashCode(): Int
```

### isEmpty

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

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the selection is empty. |

### iterator

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

```
fun iterator(): (Mutable)Iterator<K!>
```

Returns an `https://developer.android.com/reference/java/util/Iterator.html` that iterators over the selection, \*excluding\* any provisional selection.

### size

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

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | size of the selection including both final and provisional selected items. |

### toString

```
fun toString(): String!
```