{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

androidx.collection

Classes

ArrayMap

ArrayMap is a generic key->value mapping data structure that is designed to be more memory efficient than a traditional java.util.HashMap, this implementation is a version of the platform's android.util.ArrayMap that can be used on older versions of the platform.

android
ArraySet

ArraySet is a generic set data structure that is designed to be more memory efficient than a traditional HashSet.

Cmn
android
N
CircularArray

CircularArray is a generic circular array data structure that provides O(1) random read, O(1) prepend and O(1) append.

Cmn
CircularIntArray

CircularIntArray is a circular integer array data structure that provides O(1) random read, O(1) prepend and O(1) append.

Cmn
LongSparseArray

SparseArray mapping longs to Objects.

Cmn
android
N
LruCache

Static library version of android.util.LruCache.

Cmn
SimpleArrayMap

Base implementation of androidx.collection.ArrayMap that doesn't include any standard Java container API interoperability.

Cmn
SparseArrayCompat

SparseArrays map integers to Objects.

Cmn
android
N

Top-level functions summary

inline ArrayMap<K, V>
<K : Any?, V : Any?> arrayMapOf()

Returns an empty new ArrayMap.

android
ArrayMap<K, V>
<K : Any?, V : Any?> arrayMapOf(vararg pairs: Pair<K, V>)

Returns a new ArrayMap with the specified contents, given as a list of pairs where the first component is the key and the second component is the value.

android
inline ArraySet<T>
<T : Any?> arraySetOf()

Returns an empty new ArraySet.

Cmn
ArraySet<T>
<T : Any?> arraySetOf(vararg values: T)

Returns a new ArraySet with the specified contents.

Cmn
inline LruCache<K, V>
<K : Any, V : Any> lruCache(
    maxSize: Int,
    crossinline sizeOf: (key, value) -> Int,
    crossinline create: (key) -> V?,
    crossinline onEntryRemoved: (evicted: Boolean, key, oldValue, newValue?) -> Unit
)

Creates an LruCache with the given parameters.

Cmn

Extension functions summary

inline operator Boolean
<T : Any?> SparseArrayCompat<T>.contains(key: Int)

Returns true if the collection contains key.

Cmn
inline operator Boolean
<T : Any?> LongSparseArray<T>.contains(key: Long)

Returns true if the collection contains key.

Cmn
inline Unit
<T : Any?> LongSparseArray<T>.forEach(action: (key: Long, value) -> Unit)

Performs the given action for each key/value entry.

Cmn
inline Unit
<T : Any?> SparseArrayCompat<T>.forEach(action: (key: Int, value) -> Unit)

Performs the given action for each key/value entry.

Cmn
inline T
<T : Any?> SparseArrayCompat<T>.getOrDefault(key: Int, defaultValue: T)

Return the value corresponding to key, or defaultValue when not present.

Cmn
inline T
<T : Any?> LongSparseArray<T>.getOrDefault(key: Long, defaultValue: T)

Return the value corresponding to key, or defaultValue when not present.

Cmn
inline T
<T : Any?> SparseArrayCompat<T>.getOrElse(key: Int, defaultValue: () -> T)

Return the value corresponding to key, or from defaultValue when not present.

Cmn
inline T
<T : Any?> LongSparseArray<T>.getOrElse(key: Long, defaultValue: () -> T)

Return the value corresponding to key, or from defaultValue when not present.

Cmn
inline Boolean

Return true when the collection contains elements.

Cmn
inline Boolean

Return true when the collection contains elements.

Cmn
LongIterator

Return an iterator over the collection's keys.

Cmn
IntIterator

Return an iterator over the collection's keys.

Cmn
operator LongSparseArray<T>
<T : Any?> LongSparseArray<T>.plus(other: LongSparseArray<T>)

Creates a new collection by adding or replacing entries from other.

Cmn
operator SparseArrayCompat<T>

Creates a new collection by adding or replacing entries from other.

Cmn
inline operator Unit
<T : Any?> SparseArrayCompat<T>.set(key: Int, value: T)

Allows the use of the index operator for storing values in the collection.

Cmn
inline operator Unit
<T : Any?> LongSparseArray<T>.set(key: Long, value: T)

Allows the use of the index operator for storing values in the collection.

Cmn
Iterator<T>

Return an iterator over the collection's values.

Cmn
Iterator<T>

Return an iterator over the collection's values.

Cmn

Extension properties summary

Int

Returns the number of key/value pairs in the collection.

Cmn
Int

Returns the number of key/value pairs in the collection.

Cmn

Top-level functions

arrayMapOf

inline fun <K : Any?, V : Any?> arrayMapOf(): ArrayMap<K, V>

Returns an empty new ArrayMap.

arrayMapOf

fun <K : Any?, V : Any?> arrayMapOf(vararg pairs: Pair<K, V>): ArrayMap<K, V>

Returns a new ArrayMap with the specified contents, given as a list of pairs where the first component is the key and the second component is the value.

If multiple pairs have the same key, the resulting map will contain the value from the last of those pairs.

arraySetOf

inline fun <T : Any?> arraySetOf(): ArraySet<T>

Returns an empty new ArraySet.

arraySetOf

fun <T : Any?> arraySetOf(vararg values: T): ArraySet<T>

Returns a new ArraySet with the specified contents.

lruCache

inline fun <K : Any, V : Any> lruCache(
    maxSize: Int,
    crossinline sizeOf: (key, value) -> Int = { _, _ -> 1 },
    crossinline create: (key) -> V? = { null as V? },
    crossinline onEntryRemoved: (evicted: Boolean, key, oldValue, newValue?) -> Unit = { _, _, _, _ -> }
): LruCache<K, V>

Creates an LruCache with the given parameters.

Parameters
maxSize: Int

for caches that do not specify sizeOf, this is the maximum number of entries in the cache. For all other caches, this is the maximum sum of the sizes of the entries in this cache.

crossinline sizeOf: (key, value) -> Int = { _, _ -> 1 }

function that returns the size of the entry for key and value in user-defined units. The default implementation returns 1.

crossinline create: (key) -> V? = { null as V? }

a create called after a cache miss to compute a value for the corresponding key. Returns the computed value or null if no value can be computed. The default implementation returns null.

crossinline onEntryRemoved: (evicted: Boolean, key, oldValue, newValue?) -> Unit = { _, _, _, _ -> }

a function called for entries that have been evicted or removed.

See also
sizeOf
create
entryRemoved

Extension functions

contains

inline operator fun <T : Any?> SparseArrayCompat<T>.contains(key: Int): Boolean

Returns true if the collection contains key.

contains

inline operator fun <T : Any?> LongSparseArray<T>.contains(key: Long): Boolean

Returns true if the collection contains key.

forEach

inline fun <T : Any?> LongSparseArray<T>.forEach(action: (key: Long, value) -> Unit): Unit

Performs the given action for each key/value entry.

forEach

inline fun <T : Any?> SparseArrayCompat<T>.forEach(action: (key: Int, value) -> Unit): Unit

Performs the given action for each key/value entry.

getOrDefault

inline fun <T : Any?> SparseArrayCompat<T>.getOrDefault(key: Int, defaultValue: T): T

Return the value corresponding to key, or defaultValue when not present.

getOrDefault

inline fun <T : Any?> LongSparseArray<T>.getOrDefault(key: Long, defaultValue: T): T

Return the value corresponding to key, or defaultValue when not present.

getOrElse

inline fun <T : Any?> SparseArrayCompat<T>.getOrElse(key: Int, defaultValue: () -> T): T

Return the value corresponding to key, or from defaultValue when not present.

getOrElse

inline fun <T : Any?> LongSparseArray<T>.getOrElse(key: Long, defaultValue: () -> T): T

Return the value corresponding to key, or from defaultValue when not present.

isNotEmpty

inline fun <T : Any?> LongSparseArray<T>.isNotEmpty(): Boolean

Return true when the collection contains elements.

isNotEmpty

inline fun <T : Any?> SparseArrayCompat<T>.isNotEmpty(): Boolean

Return true when the collection contains elements.

keyIterator

fun <T : Any?> LongSparseArray<T>.keyIterator(): LongIterator

Return an iterator over the collection's keys.

keyIterator

fun <T : Any?> SparseArrayCompat<T>.keyIterator(): IntIterator

Return an iterator over the collection's keys.

plus

operator fun <T : Any?> LongSparseArray<T>.plus(other: LongSparseArray<T>): LongSparseArray<T>

Creates a new collection by adding or replacing entries from other.

plus

operator fun <T : Any?> SparseArrayCompat<T>.plus(other: SparseArrayCompat<T>): SparseArrayCompat<T>

Creates a new collection by adding or replacing entries from other.

set

inline operator fun <T : Any?> SparseArrayCompat<T>.set(key: Int, value: T): Unit

Allows the use of the index operator for storing values in the collection.

set

inline operator fun <T : Any?> LongSparseArray<T>.set(key: Long, value: T): Unit

Allows the use of the index operator for storing values in the collection.

valueIterator

fun <T : Any?> LongSparseArray<T>.valueIterator(): Iterator<T>

Return an iterator over the collection's values.

valueIterator

fun <T : Any?> SparseArrayCompat<T>.valueIterator(): Iterator<T>

Return an iterator over the collection's values.

Extension properties

size

val LongSparseArray<T>.sizeInt

Returns the number of key/value pairs in the collection.

size

val SparseArrayCompat<T>.sizeInt

Returns the number of key/value pairs in the collection.