# OrderedScatterSet

# OrderedScatterSet

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/collection/OrderedScatterSet "View this page in Java")
Common/AllAndroid/JVMNative/C/iOSJavaScript
  - Cmn  

  ```
  sealed class OrderedScatterSet<E : Any?>
```  
Known direct subclasses  
[MutableOrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/MutableOrderedScatterSet)  

|-------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [MutableOrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/MutableOrderedScatterSet) | [MutableOrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/MutableOrderedScatterSet)is a container with a[MutableSet](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html)-like interface based on a flat hash table implementation that preserves the insertion order for iteration. |

*** ** * ** ***

[OrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet)is a container with a[Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)-like interface based on a flat hash table implementation that preserves the insertion order for iteration. 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 guarantees the order of the elements when iterating over them using[forEach](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#forEach(kotlin.Function1))or the iterator provided by[asSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#asSet()).

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

**Note** : when a[Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)is absolutely necessary, you can use the method[asSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#asSet())to create a thin wrapper around an[OrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet). Please refer to[asSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#asSet())for more details and caveats.  

|                                                        See also                                                         |
|-------------------------------------------------------------------------------------------------------------------------|---|
| [MutableOrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/MutableOrderedScatterSet) |   |

## Summary

|                                                                                                ### Protected constructors                                                                                                |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| `<E : `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?> `[OrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#OrderedScatterSet())`()` | Cmn |

|                                                                                   ### Public functions                                                                                    |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| `inline `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                              | [all](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#all(kotlin.Function1))`(predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Returns true if all elements match the given[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#all(kotlin.Function1)).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Cmn |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                       | [any](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#any())`()` Returns`true`if this set has at least one element.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Cmn |
| `inline `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                              | [any](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#any(kotlin.Function1))`(predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Returns true if at least one element matches the given[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#any(kotlin.Function1)).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Cmn |
| [Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)`<E>`                                                                                              | [asSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#asSet())`()` Wraps this[OrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet)with a[Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)interface.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | Cmn |
| `operator `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                            | [contains](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#contains(kotlin.Any))`(element: E)` Returns true if the specified[element](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#contains(kotlin.Any))is present in this hash set, false otherwise.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Cmn |
| `@`[IntRange](https://developer.android.com/reference/kotlin/androidx/annotation/IntRange)`(from = 0) `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)        | [count](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#count())`()` Returns the number of elements in this set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Cmn |
| `inline @`[IntRange](https://developer.android.com/reference/kotlin/androidx/annotation/IntRange)`(from = 0) `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [count](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#count(kotlin.Function1))`(predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Returns the number of elements matching the given[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#count(kotlin.Function1)).The order in which the predicate is called over the elements is arbitrary.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Cmn |
| `open operator `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                       | [equals](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#equals(kotlin.Any))`(other: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?)` Compares the specified object[other](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#equals(kotlin.Any))with this hash set for equality.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Cmn |
| `E`                                                                                                                                                                                       | [first](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#first())`()` Returns the first element in the collection.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | Cmn |
| `inline E`                                                                                                                                                                                | [first](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#first(kotlin.Function1))`(predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Returns the first element in insertion order in the collection for which[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#first(kotlin.Function1))returns`true`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Cmn |
| `inline E?`                                                                                                                                                                               | [firstOrNull](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#firstOrNull(kotlin.Function1))`(predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Returns the first element in insertion order in the collection for which[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#firstOrNull(kotlin.Function1))returns`true`or`null`if there are no elements that match[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#firstOrNull(kotlin.Function1)).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | Cmn |
| `inline `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                    | [forEach](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#forEach(kotlin.Function1))`(block: (element) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)`)` Iterates over every element stored in this set by invoking the specified[block](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#forEach(kotlin.Function1))lambda.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Cmn |
| `inline `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                    | [forEachReverse](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#forEachReverse(kotlin.Function1))`(block: (element) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)`)` Iterates over every element stored in this set by invoking the specified[block](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#forEachReverse(kotlin.Function1))lambda.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Cmn |
| `open `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                        | [hashCode](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#hashCode())`()` Returns the hash code value for this set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Cmn |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                       | [isEmpty](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#isEmpty())`()` Indicates whether this set is empty.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Cmn |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                       | [isNotEmpty](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#isNotEmpty())`()` Returns`true`if this set is not empty.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Cmn |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                                                                         | [joinToString](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1))`(` ` separator: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`,` ` prefix: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`,` ` postfix: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`,` ` limit: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` truncated: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`,` ` transform: ((E) `->` `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`)?` `)` Creates a String from the elements separated by[separator](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1))and using[prefix](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1))before and[postfix](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1))after, if supplied. | Cmn |
| `E`                                                                                                                                                                                       | [last](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#last())`()` Returns the last element in the collection.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Cmn |
| `inline E`                                                                                                                                                                                | [last](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#last(kotlin.Function1))`(predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Returns the last element in insertion order in the collection for which[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#last(kotlin.Function1))returns`true`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | Cmn |
| `inline E?`                                                                                                                                                                               | [lastOrNull](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#lastOrNull(kotlin.Function1))`(predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Returns the first element in insertion order in the collection for which[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#lastOrNull(kotlin.Function1))returns`true`or`null`if there are no elements that match[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#lastOrNull(kotlin.Function1)).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Cmn |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                       | [none](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#none())`()` Returns`true`if this set has no elements.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Cmn |
| `inline `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<E>`                                                                                   | [toList](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#toList())`()` Returns a new list containing this set's entries, in insertion order.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Cmn |
| `open `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                                                                  | [toString](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#toString())`()` Returns a string representation of this set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Cmn |

|                            ### Public properties                            |
|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [capacity](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#capacity()) Returns the number of elements that can be stored in this set without requiring internal storage reallocation. | Cmn |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [size](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#size()) Returns the number of elements in this set.                                                                            | Cmn |

## Protected constructors

### OrderedScatterSet

Cmn  

```
protected <E : Any?> OrderedScatterSet()
```

## Public functions

### all

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

```
inline fun all(predicate: (element) -> Boolean): Boolean
```

Returns true if all elements match the given[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#all(kotlin.Function1)). If there are no elements in the set,`true`is returned. The order in which the predicate is called over the elements is arbitrary.  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------|
| `predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | called for elements in the set to determine if it returns return`true`for all elements. |

### any

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

```
fun any(): Boolean
```

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

### any

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

```
inline fun any(predicate: (element) -> Boolean): Boolean
```

Returns true if at least one element matches the given[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#any(kotlin.Function1)). The order in which the predicate is called over the elements is arbitrary.  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------|
| `predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | called for elements in the set to determine if it returns`true`for any elements. |

### asSet

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

```
fun asSet(): Set<E>
```

Wraps this[OrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet)with a[Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)interface. The[Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)is backed by the[OrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet), so changes to the[OrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet)are reflected in the[Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html). If the[OrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet)is modified while an iteration over the[Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)is in progress, the results of the iteration are undefined.

**Note** : while this method is useful to use this[OrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet)with APIs accepting[Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)interfaces, it is less efficient to do so than to use[OrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet)'s APIs directly. While the[Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)implementation returned by this method tries to be as efficient as possible, the semantics of[Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)may require the allocation of temporary objects for access and iteration.  

### contains

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

```
operator fun contains(element: E): Boolean
```

Returns true if the specified[element](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#contains(kotlin.Any))is present in this hash set, false otherwise.  

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

### count

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

```
fun count(): @IntRange(from = 0) Int
```

Returns the number of elements in this set.  

### count

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

```
inline fun count(predicate: (element) -> Boolean): @IntRange(from = 0) Int
```

Returns the number of elements matching the given[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#count(kotlin.Function1)).The order in which the predicate is called over the elements is arbitrary.  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| `predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Called for all elements in the set to count the number for which it returns`true`. |

### equals

Cmn  

```
open operator fun equals(other: Any?): Boolean
```

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

- Is a[OrderedScatterSet](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet)

- Has the same[size](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#size())as this set

- Contains elements equal to this set's elements

### first

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

```
fun first(): E
```

Returns the first element in the collection.  

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

### first

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

```
inline fun first(predicate: (element) -> Boolean): E
```

Returns the first element in insertion order in the collection for which[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#first(kotlin.Function1))returns`true`.  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|--------------------------------------------------|
| `predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | called with each element until it returns`true`. |

| Returns |
|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `E`     | The element for which[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#first(kotlin.Function1))returns`true`. |

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

### firstOrNull

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

```
inline fun firstOrNull(predicate: (element) -> Boolean): E?
```

Returns the first element in insertion order in the collection for which[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#firstOrNull(kotlin.Function1))returns`true`or`null`if there are no elements that match[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#firstOrNull(kotlin.Function1)).  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|--------------------------------------------------|
| `predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | called with each element until it returns`true`. |

| Returns |
|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `E?`    | The element for which[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#firstOrNull(kotlin.Function1))returns`true`or`null`if there are no elements in the set or[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#firstOrNull(kotlin.Function1))returned`false`for every element in the set. |

### forEach

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

```
inline fun forEach(block: (element) -> Unit): Unit
```

Iterates over every element stored in this set by invoking the specified[block](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#forEach(kotlin.Function1))lambda. The iteration order is the same as the insertion order. It is safe to remove the element passed to[block](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#forEach(kotlin.Function1))during iteration.  

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|-------------------------------------|
| `block: (element) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | called with each element in the set |

### forEachReverse

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

```
inline fun forEachReverse(block: (element) -> Unit): Unit
```

Iterates over every element stored in this set by invoking the specified[block](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#forEachReverse(kotlin.Function1))lambda. The iteration order is the reverse of the insertion order. It is safe to remove the element passed to[block](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#forEachReverse(kotlin.Function1))during iteration.  

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|-------------------------------------|
| `block: (element) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | called with each element in the set |

### hashCode

Cmn  

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

Returns the hash code value for this set. The hash code of a set is based on the sum of the hash codes of the elements in the set, where the hash code of a null element is defined to be zero.  

### isEmpty

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

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

Indicates whether this set is empty.  

### isNotEmpty

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

```
fun isNotEmpty(): Boolean
```

Returns`true`if this set is not empty.  

### joinToString

Cmn  

```
fun joinToString(
    separator: CharSequence = ", ",
    prefix: CharSequence = "",
    postfix: CharSequence = "",
    limit: Int = -1,
    truncated: CharSequence = "...",
    transform: ((E) -> CharSequence)? = null
): String
```

Creates a String from the elements separated by[separator](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1))and using[prefix](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1))before and[postfix](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1))after, if supplied.

When a non-negative value of[limit](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1))is provided, a maximum of[limit](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#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[limit](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1))items, the string is terminated with[truncated](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1)).

[transform](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#joinToString(kotlin.CharSequence,kotlin.CharSequence,kotlin.CharSequence,kotlin.Int,kotlin.CharSequence,kotlin.Function1))may be supplied to convert each element to a custom String.  

### last

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

```
fun last(): E
```

Returns the last element in the collection.  

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

### last

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

```
inline fun last(predicate: (element) -> Boolean): E
```

Returns the last element in insertion order in the collection for which[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#last(kotlin.Function1))returns`true`.  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|--------------------------------------------------|
| `predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | called with each element until it returns`true`. |

| Returns |
|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `E`     | The element for which[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#last(kotlin.Function1))returns`true`. |

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

### lastOrNull

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

```
inline fun lastOrNull(predicate: (element) -> Boolean): E?
```

Returns the first element in insertion order in the collection for which[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#lastOrNull(kotlin.Function1))returns`true`or`null`if there are no elements that match[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#lastOrNull(kotlin.Function1)).  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|--------------------------------------------------|
| `predicate: (element) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | called with each element until it returns`true`. |

| Returns |
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `E?`    | The element for which[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#lastOrNull(kotlin.Function1))returns`true`or`null`if there are no elements in the set or[predicate](https://developer.android.com/reference/kotlin/androidx/collection/OrderedScatterSet#lastOrNull(kotlin.Function1))returned`false`for every element in the set. |

### none

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

```
fun none(): Boolean
```

Returns`true`if this set has no elements.  

### toList

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

```
inline fun toList(): List<E>
```

Returns a new list containing this set's entries, in insertion order.  

### toString

Cmn  

```
open fun toString(): String
```

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

## Public properties

### capacity

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

```
val capacity: Int
```

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

### size

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

```
val size: Int
```

Returns the number of elements in this set.