blob: 31fae8001a12888c3b789755f50faf3198d6e4c9 [file]
<html devsite="true">
<head>
<title>LongSparseArray</title>
{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<div itemscope="" itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="LongSparseArray">
<meta itemprop="path" content="androidx.collection">
<meta itemprop="property" content="append(kotlin.Long,kotlin.Any)">
<meta itemprop="property" content="clear()">
<meta itemprop="property" content="clone()">
<meta itemprop="property" content="containsKey(kotlin.Long)">
<meta itemprop="property" content="containsValue(kotlin.Any)">
<meta itemprop="property" content="delete(kotlin.Long)">
<meta itemprop="property" content="get(kotlin.Long)">
<meta itemprop="property" content="get(kotlin.Long,kotlin.Any)">
<meta itemprop="property" content="indexOfKey(kotlin.Long)">
<meta itemprop="property" content="indexOfValue(kotlin.Any)">
<meta itemprop="property" content="isEmpty()">
<meta itemprop="property" content="keyAt(kotlin.Int)">
<meta itemprop="property" content="put(kotlin.Long,kotlin.Any)">
<meta itemprop="property" content="putAll(androidx.collection.LongSparseArray)">
<meta itemprop="property" content="putIfAbsent(kotlin.Long,kotlin.Any)">
<meta itemprop="property" content="remove(kotlin.Long)">
<meta itemprop="property" content="remove(kotlin.Long,kotlin.Any)">
<meta itemprop="property" content="removeAt(kotlin.Int)">
<meta itemprop="property" content="replace(kotlin.Long,kotlin.Any)">
<meta itemprop="property" content="replace(kotlin.Long,kotlin.Any,kotlin.Any)">
<meta itemprop="property" content="setValueAt(kotlin.Int,kotlin.Any)">
<meta itemprop="property" content="size()">
<meta itemprop="property" content="toString()">
<meta itemprop="property" content="valueAt(kotlin.Int)">
<meta itemprop="property" content="(androidx.collection.LongSparseArray).contains(kotlin.Long)">
<meta itemprop="property" content="(androidx.collection.LongSparseArray).forEach(kotlin.Function2)">
<meta itemprop="property" content="(androidx.collection.LongSparseArray).getOrDefault(kotlin.Long,kotlin.Any)">
<meta itemprop="property" content="(androidx.collection.LongSparseArray).getOrElse(kotlin.Long,kotlin.Function0)">
<meta itemprop="property" content="(androidx.collection.LongSparseArray).getSize()">
<meta itemprop="property" content="(androidx.collection.LongSparseArray).isNotEmpty()">
<meta itemprop="property" content="(androidx.collection.LongSparseArray).keyIterator()">
<meta itemprop="property" content="(androidx.collection.LongSparseArray).plus(androidx.collection.LongSparseArray)">
<meta itemprop="property" content="(androidx.collection.LongSparseArray).set(kotlin.Long,kotlin.Any)">
<meta itemprop="property" content="(androidx.collection.LongSparseArray).valueIterator()">
<meta itemprop="language" content="JAVA">
</div>
<div id="header-block">
<div>
<h1>LongSparseArray</h1>
</div>
<div id="metadata-info-block">
<div id="source-link"><a href="https://cs.android.com/search?q=file:androidx/collection/LongSparseArray.+class:androidx.collection.LongSparseArray&amp;ss=androidx/platform/frameworks/support" class="external">View Source</a></div>
</div>
</div>
<div id="refdoc-switcher-placeholder"></div>
<p>
<pre>public class <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;E&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt;</pre>
</p>
<hr>
<p>SparseArray mapping longs to Objects. Unlike a normal array of Objects, there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Longs to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping.</p>
<p>Note that this container keeps its mappings in an array data structure, using a binary search to find keys. The implementation is not intended to be appropriate for data structures that may contain large numbers of items. It is generally slower than a traditional HashMap, since lookups require a binary search and adds and removes require inserting and deleting entries in the array. For containers holding up to hundreds of items, the performance difference is not significant, less than 50%.</p>
<p>To help with performance, the container includes an optimization when removing keys: instead of compacting its array immediately, it leaves the removed entry marked as deleted. The entry can then be re-used for the same key, or compacted later in a single garbage collection step of all removed entries. This garbage collection will need to be performed at any time the array needs to be grown or the map size or entry values are retrieved.</p>
<p>It is possible to iterate over the items in this container using <code><a href="/reference/androidx/collection/LongSparseArray.html#keyAt(kotlin.Int)">keyAt</a></code> and <code><a href="/reference/androidx/collection/LongSparseArray.html#valueAt(kotlin.Int)">valueAt</a></code>. Iterating over the keys using <code><a href="/reference/androidx/collection/LongSparseArray.html#keyAt(kotlin.Int)">keyAt</a></code> with ascending values of the index will return the keys in ascending order, or the values corresponding to the keys in ascending order in the case of <code><a href="/reference/androidx/collection/LongSparseArray.html#valueAt(kotlin.Int)">valueAt</a></code>.</p>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public constructors</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td>
<div><code>&lt;E&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArray.html#LongSparseArray(kotlin.Int)">LongSparseArray</a>(int&nbsp;initialCapacity)</code></div>
<p>Creates a new <code><a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a></code> containing no mappings that will not require any additional memory allocation to store the specified number of mappings.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public methods</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>void</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#append(kotlin.Long,kotlin.Any)">append</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</code></div>
<p>Puts a key/value pair into the array, optimizing for the case where the key is greater than all existing keys in the array.</p>
</td>
</tr>
<tr>
<td><code>void</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#clear()">clear</a>()</code></div>
<p>Removes all key-value mappings from this <code><a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a></code>.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&gt;</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#clone()">clone</a>()</code></div>
</td>
</tr>
<tr>
<td><code>boolean</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#containsKey(kotlin.Long)">containsKey</a>(long&nbsp;key)</code></div>
<p>Returns <code>true</code> if the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#containsKey(kotlin.Long)">key</a></code> is mapped.</p>
</td>
</tr>
<tr>
<td><code>boolean</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#containsValue(kotlin.Any)">containsValue</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</code></div>
<p>Returns <code>true</code> if the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#containsValue(kotlin.Any)">value</a></code> is mapped from any key.</p>
</td>
</tr>
<tr>
<td><code>void</code></td>
<td>
<div><code><span><del><a href="/reference/androidx/collection/LongSparseArray.html#delete(kotlin.Long)">delete</a></del></span>(long&nbsp;key)</code></div>
<p><strong>This method is deprecated.</strong> Alias for `remove(key)`.</p>
</td>
</tr>
<tr>
<td><code>E</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#get(kotlin.Long)">get</a>(long&nbsp;key)</code></div>
<p>Gets the value mapped from the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#get(kotlin.Long)">key</a></code>, or <code>null</code> if no such mapping has been made.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#get(kotlin.Long,kotlin.Any)">get</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;defaultValue)</code></div>
<p>Gets the value mapped from the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#get(kotlin.Long,kotlin.Any)">key</a></code>, or <code><a href="/reference/androidx/collection/LongSparseArray.html#get(kotlin.Long,kotlin.Any)">defaultValue</a></code> if no such mapping has been made.</p>
</td>
</tr>
<tr>
<td><code>int</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#indexOfKey(kotlin.Long)">indexOfKey</a>(long&nbsp;key)</code></div>
<p>Returns the index for which <code><a href="/reference/androidx/collection/LongSparseArray.html#keyAt(kotlin.Int)">keyAt</a></code> would return the specified key, or a negative number if the specified key is not mapped.</p>
</td>
</tr>
<tr>
<td><code>int</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#indexOfValue(kotlin.Any)">indexOfValue</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</code></div>
<p>Returns an index for which <code><a href="/reference/androidx/collection/LongSparseArray.html#valueAt(kotlin.Int)">valueAt</a></code> would return the specified key, or a negative number if no keys map to the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#indexOfValue(kotlin.Any)">value</a></code>.</p>
</td>
</tr>
<tr>
<td><code>boolean</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#isEmpty()">isEmpty</a>()</code></div>
<p>Return <code>true</code> if <code><a href="/reference/androidx/collection/LongSparseArray.html#size()">size</a></code> is 0.</p>
</td>
</tr>
<tr>
<td><code>long</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#keyAt(kotlin.Int)">keyAt</a>(int&nbsp;index)</code></div>
<p>Given an index in the range <code>0...size()-1</code>, returns the key from the <code>index</code>th key-value mapping that this <code><a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a></code> stores.</p>
</td>
</tr>
<tr>
<td><code>void</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#put(kotlin.Long,kotlin.Any)">put</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</code></div>
<p>Adds a mapping from the specified key to the specified value, replacing the previous mapping from the specified key if there was one.</p>
</td>
</tr>
<tr>
<td><code>void</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#putAll(androidx.collection.LongSparseArray)">putAll</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&gt;&nbsp;other)</code></div>
<p>Copies all of the mappings from <code><a href="/reference/androidx/collection/LongSparseArray.html#putAll(androidx.collection.LongSparseArray)">other</a></code> to this map.</p>
</td>
</tr>
<tr>
<td><code>E</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#putIfAbsent(kotlin.Long,kotlin.Any)">putIfAbsent</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</code></div>
<p>Add a new value to the array map only if the key does not already have a value or it is mapped to <code>null</code>.</p>
</td>
</tr>
<tr>
<td><code>void</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#remove(kotlin.Long)">remove</a>(long&nbsp;key)</code></div>
<p>Removes the mapping from the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#remove(kotlin.Long)">key</a></code>, if there was any.</p>
</td>
</tr>
<tr>
<td><code>boolean</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#remove(kotlin.Long,kotlin.Any)">remove</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</code></div>
<p>Remove an existing key from the array map only if it is currently mapped to <code><a href="/reference/androidx/collection/LongSparseArray.html#remove(kotlin.Long,kotlin.Any)">value</a></code>.</p>
</td>
</tr>
<tr>
<td><code>void</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#removeAt(kotlin.Int)">removeAt</a>(int&nbsp;index)</code></div>
<p>Removes the mapping at the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#removeAt(kotlin.Int)">index</a></code>.</p>
</td>
</tr>
<tr>
<td><code>E</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#replace(kotlin.Long,kotlin.Any)">replace</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</code></div>
<p>Replace the mapping for <code><a href="/reference/androidx/collection/LongSparseArray.html#replace(kotlin.Long,kotlin.Any)">key</a></code> only if it is already mapped to a value.</p>
</td>
</tr>
<tr>
<td><code>boolean</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#replace(kotlin.Long,kotlin.Any,kotlin.Any)">replace</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;oldValue,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;newValue)</code></div>
<p>Replace the mapping for <code><a href="/reference/androidx/collection/LongSparseArray.html#replace(kotlin.Long,kotlin.Any,kotlin.Any)">key</a></code> only if it is already mapped to a value.</p>
</td>
</tr>
<tr>
<td><code>void</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#setValueAt(kotlin.Int,kotlin.Any)">setValueAt</a>(int&nbsp;index,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</code></div>
<p>Given an index in the range <code>0...size()-1</code>, sets a new value for the <code>index</code>th key-value mapping that this <code><a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a></code> stores.</p>
</td>
</tr>
<tr>
<td><code>int</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#size()">size</a>()</code></div>
<p>Returns the number of key-value mappings that this <code><a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a></code> currently stores.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/lang/String.html">String</a></code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#toString()">toString</a>()</code></div>
<p>Returns a string representation of the object.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArray.html#valueAt(kotlin.Int)">valueAt</a>(int&nbsp;index)</code></div>
<p>Given an index in the range <code>0...size()-1</code>, returns the value from the <code>index</code>th key-value mapping that this <code><a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a></code> stores.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Extension functions</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>final boolean</code></td>
<td>
<div><code>&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).contains(kotlin.Long)">contains</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;key<br>)</code></div>
<p>Returns true if the collection contains <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).contains(kotlin.Long)">key</a></code>.</p>
</td>
</tr>
<tr>
<td><code>final void</code></td>
<td>
<div><code>&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).forEach(kotlin.Function2)">forEach</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function2&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/lang/Long.html">Long</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> value,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;action<br>)</code></div>
<p>Performs the given <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).forEach(kotlin.Function2)">action</a></code> for each key/value entry.</p>
</td>
</tr>
<tr>
<td><code>final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T</code></td>
<td>
<div><code>&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).getOrDefault(kotlin.Long,kotlin.Any)">getOrDefault</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;key,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&nbsp;defaultValue<br>)</code></div>
<p>Return the value corresponding to <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).getOrDefault(kotlin.Long,kotlin.Any)">key</a></code>, or <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).getOrDefault(kotlin.Long,kotlin.Any)">defaultValue</a></code> when not present.</p>
</td>
</tr>
<tr>
<td><code>final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T</code></td>
<td>
<div><code>&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).getOrElse(kotlin.Long,kotlin.Function0)">getOrElse</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;key,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;defaultValue<br>)</code></div>
<p>Return the value corresponding to <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).getOrElse(kotlin.Long,kotlin.Function0)">key</a></code>, or from <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).getOrElse(kotlin.Long,kotlin.Function0)">defaultValue</a></code> when not present.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).getSize()">getSize</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver)</code></div>
<p>Returns the number of key/value pairs in the collection.</p>
</td>
</tr>
<tr>
<td><code>final boolean</code></td>
<td>
<div><code>&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).isNotEmpty()">isNotEmpty</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver<br>)</code></div>
<p>Return true when the collection contains elements.</p>
</td>
</tr>
<tr>
<td><code>final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-long-iterator/index.html">LongIterator</a></code></td>
<td>
<div><code>&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).keyIterator()">keyIterator</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver<br>)</code></div>
<p>Return an iterator over the collection's keys.</p>
</td>
</tr>
<tr>
<td><code>final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;</code></td>
<td>
<div><code>&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).plus(androidx.collection.LongSparseArray)">plus</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;other<br>)</code></div>
<p>Creates a new collection by adding or replacing entries from <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).plus(androidx.collection.LongSparseArray)">other</a></code>.</p>
</td>
</tr>
<tr>
<td><code>final void</code></td>
<td>
<div><code>&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).set(kotlin.Long,kotlin.Any)">set</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;key,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&nbsp;value<br>)</code></div>
<p>Allows the use of the index operator for storing values in the collection.</p>
</td>
</tr>
<tr>
<td><code>final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/util/Iterator.html">Iterator</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;</code></td>
<td>
<div><code>&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).valueIterator()">valueIterator</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver<br>)</code></div>
<p>Return an iterator over the collection's values.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="list">
<h2>Public constructors</h2>
<div class="api-item"><a name="LongSparseArray-kotlin.Int-"></a><a name="longsparsearray"></a>
<div class="api-name-block">
<div>
<h3 id="LongSparseArray(kotlin.Int)">LongSparseArray</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;&lt;E&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArray.html#LongSparseArray(kotlin.Int)">LongSparseArray</a>(int&nbsp;initialCapacity)</pre>
<p>Creates a new <code><a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a></code> containing no mappings that will not require any additional memory allocation to store the specified number of mappings. If you supply an initial capacity of 0, the sparse array will be initialized with a light-weight representation not requiring any additional array allocations.</p>
</div>
</div>
<div class="list">
<h2>Public methods</h2>
<div class="api-item"><a name="append(kotlin.Long, kotlin.Any)"></a><a name="append-kotlin.Long-kotlin.Any-"></a><a name="append"></a>
<div class="api-name-block">
<div>
<h3 id="append(kotlin.Long,kotlin.Any)">append</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;void&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#append(kotlin.Long,kotlin.Any)">append</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</pre>
<p>Puts a key/value pair into the array, optimizing for the case where the key is greater than all existing keys in the array.</p>
</div>
<div class="api-item"><a name="clear--"></a><a name="clear"></a>
<div class="api-name-block">
<div>
<h3 id="clear()">clear</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;void&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#clear()">clear</a>()</pre>
<p>Removes all key-value mappings from this <code><a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a></code>.</p>
</div>
<div class="api-item"><a name="clone--"></a><a name="clone"></a>
<div class="api-name-block">
<div>
<h3 id="clone()">clone</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&gt;&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#clone()">clone</a>()</pre>
</div>
<div class="api-item"><a name="containsKey-kotlin.Long-"></a><a name="containskey"></a>
<div class="api-name-block">
<div>
<h3 id="containsKey(kotlin.Long)">containsKey</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;boolean&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#containsKey(kotlin.Long)">containsKey</a>(long&nbsp;key)</pre>
<p>Returns <code>true</code> if the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#containsKey(kotlin.Long)">key</a></code> is mapped.</p>
</div>
<div class="api-item"><a name="containsValue-kotlin.Any-"></a><a name="containsvalue"></a>
<div class="api-name-block">
<div>
<h3 id="containsValue(kotlin.Any)">containsValue</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;boolean&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#containsValue(kotlin.Any)">containsValue</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</pre>
<p>Returns <code>true</code> if the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#containsValue(kotlin.Any)">value</a></code> is mapped from any key.</p>
</div>
<div class="api-item"><a name="delete-kotlin.Long-"></a><a name="delete"></a>
<div class="api-name-block">
<div>
<h3 id="delete(kotlin.Long)">delete</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;void&nbsp;<span><del><a href="/reference/androidx/collection/LongSparseArray.html#delete(kotlin.Long)">delete</a></del></span>(long&nbsp;key)</pre>
<aside class="caution"><strong>This method is deprecated.</strong><br>Alias for `remove(key)`.</aside>
<p>Removes the mapping from the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#delete(kotlin.Long)">key</a></code>, if there was any.</p>
</div>
<div class="api-item"><a name="get-kotlin.Long-"></a><a name="get"></a>
<div class="api-name-block">
<div>
<h3 id="get(kotlin.Long)">get</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;E&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#get(kotlin.Long)">get</a>(long&nbsp;key)</pre>
<p>Gets the value mapped from the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#get(kotlin.Long)">key</a></code>, or <code>null</code> if no such mapping has been made.</p>
</div>
<div class="api-item"><a name="get(kotlin.Long, kotlin.Any)"></a><a name="get-kotlin.Long-kotlin.Any-"></a><a name="get"></a>
<div class="api-name-block">
<div>
<h3 id="get(kotlin.Long,kotlin.Any)">get</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#get(kotlin.Long,kotlin.Any)">get</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;defaultValue)</pre>
<p>Gets the value mapped from the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#get(kotlin.Long,kotlin.Any)">key</a></code>, or <code><a href="/reference/androidx/collection/LongSparseArray.html#get(kotlin.Long,kotlin.Any)">defaultValue</a></code> if no such mapping has been made.</p>
</div>
<div class="api-item"><a name="indexOfKey-kotlin.Long-"></a><a name="indexofkey"></a>
<div class="api-name-block">
<div>
<h3 id="indexOfKey(kotlin.Long)">indexOfKey</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;int&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#indexOfKey(kotlin.Long)">indexOfKey</a>(long&nbsp;key)</pre>
<p>Returns the index for which <code><a href="/reference/androidx/collection/LongSparseArray.html#keyAt(kotlin.Int)">keyAt</a></code> would return the specified key, or a negative number if the specified key is not mapped.</p>
</div>
<div class="api-item"><a name="indexOfValue-kotlin.Any-"></a><a name="indexofvalue"></a>
<div class="api-name-block">
<div>
<h3 id="indexOfValue(kotlin.Any)">indexOfValue</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;int&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#indexOfValue(kotlin.Any)">indexOfValue</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</pre>
<p>Returns an index for which <code><a href="/reference/androidx/collection/LongSparseArray.html#valueAt(kotlin.Int)">valueAt</a></code> would return the specified key, or a negative number if no keys map to the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#indexOfValue(kotlin.Any)">value</a></code>.</p>
<p>Beware that this is a linear search, unlike lookups by key, and that multiple keys can map to the same value and this will find only one of them.</p>
</div>
<div class="api-item"><a name="isEmpty--"></a><a name="isempty"></a>
<div class="api-name-block">
<div>
<h3 id="isEmpty()">isEmpty</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;boolean&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#isEmpty()">isEmpty</a>()</pre>
<p>Return <code>true</code> if <code><a href="/reference/androidx/collection/LongSparseArray.html#size()">size</a></code> is 0.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>boolean</code></td>
<td>
<p><code>true</code> if <code><a href="/reference/androidx/collection/LongSparseArray.html#size()">size</a></code> is 0.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="keyAt-kotlin.Int-"></a><a name="keyat"></a>
<div class="api-name-block">
<div>
<h3 id="keyAt(kotlin.Int)">keyAt</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;long&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#keyAt(kotlin.Int)">keyAt</a>(int&nbsp;index)</pre>
<p>Given an index in the range <code>0...size()-1</code>, returns the key from the <code>index</code>th key-value mapping that this <code><a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a></code> stores.</p>
<p>The keys corresponding to indices in ascending order are guaranteed to be in ascending order, e.g., <code>keyAt(0)</code> will return the smallest key and <code>keyAt(size()-1)</code> will return the largest key.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Throws</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html">kotlin.IllegalArgumentException</a></code></td>
<td>
<p>if <code><a href="/reference/androidx/collection/LongSparseArray.html#keyAt(kotlin.Int)">index</a></code> is not in the range <code>0...size()-1</code></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="put(kotlin.Long, kotlin.Any)"></a><a name="put-kotlin.Long-kotlin.Any-"></a><a name="put"></a>
<div class="api-name-block">
<div>
<h3 id="put(kotlin.Long,kotlin.Any)">put</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;void&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#put(kotlin.Long,kotlin.Any)">put</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</pre>
<p>Adds a mapping from the specified key to the specified value, replacing the previous mapping from the specified key if there was one.</p>
</div>
<div class="api-item"><a name="putAll-androidx.collection.LongSparseArray-"></a><a name="putall"></a>
<div class="api-name-block">
<div>
<h3 id="putAll(androidx.collection.LongSparseArray)">putAll</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;void&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#putAll(androidx.collection.LongSparseArray)">putAll</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&gt;&nbsp;other)</pre>
<p>Copies all of the mappings from <code><a href="/reference/androidx/collection/LongSparseArray.html#putAll(androidx.collection.LongSparseArray)">other</a></code> to this map. The effect of this call is equivalent to that of calling <code><a href="/reference/androidx/collection/LongSparseArray.html#put(kotlin.Long,kotlin.Any)">put</a></code> on this map once for each mapping from key to value in <code><a href="/reference/androidx/collection/LongSparseArray.html#putAll(androidx.collection.LongSparseArray)">other</a></code>.</p>
</div>
<div class="api-item"><a name="putIfAbsent(kotlin.Long, kotlin.Any)"></a><a name="putIfAbsent-kotlin.Long-kotlin.Any-"></a><a name="putifabsent"></a>
<div class="api-name-block">
<div>
<h3 id="putIfAbsent(kotlin.Long,kotlin.Any)">putIfAbsent</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;E&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#putIfAbsent(kotlin.Long,kotlin.Any)">putIfAbsent</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</pre>
<p>Add a new value to the array map only if the key does not already have a value or it is mapped to <code>null</code>.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>long&nbsp;key</code></td>
<td>
<p>The key under which to store the value.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value</code></td>
<td>
<p>The value to store for the given key.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>E</code></td>
<td>
<p>Returns the value that was stored for the given key, or <code>null</code> if there was no such key.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="remove-kotlin.Long-"></a><a name="remove"></a>
<div class="api-name-block">
<div>
<h3 id="remove(kotlin.Long)">remove</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;void&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#remove(kotlin.Long)">remove</a>(long&nbsp;key)</pre>
<p>Removes the mapping from the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#remove(kotlin.Long)">key</a></code>, if there was any.</p>
</div>
<div class="api-item"><a name="remove(kotlin.Long, kotlin.Any)"></a><a name="remove-kotlin.Long-kotlin.Any-"></a><a name="remove"></a>
<div class="api-name-block">
<div>
<h3 id="remove(kotlin.Long,kotlin.Any)">remove</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;boolean&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#remove(kotlin.Long,kotlin.Any)">remove</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</pre>
<p>Remove an existing key from the array map only if it is currently mapped to <code><a href="/reference/androidx/collection/LongSparseArray.html#remove(kotlin.Long,kotlin.Any)">value</a></code>.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>long&nbsp;key</code></td>
<td>
<p>The key of the mapping to remove.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value</code></td>
<td>
<p>The value expected to be mapped to the key.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>boolean</code></td>
<td>
<p>Returns <code>true</code> if the mapping was removed.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="removeAt-kotlin.Int-"></a><a name="removeat"></a>
<div class="api-name-block">
<div>
<h3 id="removeAt(kotlin.Int)">removeAt</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;void&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#removeAt(kotlin.Int)">removeAt</a>(int&nbsp;index)</pre>
<p>Removes the mapping at the specified <code><a href="/reference/androidx/collection/LongSparseArray.html#removeAt(kotlin.Int)">index</a></code>.</p>
</div>
<div class="api-item"><a name="replace(kotlin.Long, kotlin.Any)"></a><a name="replace-kotlin.Long-kotlin.Any-"></a><a name="replace"></a>
<div class="api-name-block">
<div>
<h3 id="replace(kotlin.Long,kotlin.Any)">replace</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;E&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#replace(kotlin.Long,kotlin.Any)">replace</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</pre>
<p>Replace the mapping for <code><a href="/reference/androidx/collection/LongSparseArray.html#replace(kotlin.Long,kotlin.Any)">key</a></code> only if it is already mapped to a value.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>long&nbsp;key</code></td>
<td>
<p>The key of the mapping to replace.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value</code></td>
<td>
<p>The value to store for the given key.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>E</code></td>
<td>
<p>Returns the previous mapped value or <code>null</code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="replace(kotlin.Long, kotlin.Any, kotlin.Any)"></a><a name="replace-kotlin.Long-kotlin.Any-kotlin.Any-"></a><a name="replace"></a>
<div class="api-name-block">
<div>
<h3 id="replace(kotlin.Long,kotlin.Any,kotlin.Any)">replace</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;boolean&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#replace(kotlin.Long,kotlin.Any,kotlin.Any)">replace</a>(long&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;oldValue,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;newValue)</pre>
<p>Replace the mapping for <code><a href="/reference/androidx/collection/LongSparseArray.html#replace(kotlin.Long,kotlin.Any,kotlin.Any)">key</a></code> only if it is already mapped to a value.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>long&nbsp;key</code></td>
<td>
<p>The key of the mapping to replace.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;oldValue</code></td>
<td>
<p>The value expected to be mapped to the key.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;newValue</code></td>
<td>
<p>The value to store for the given key.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>boolean</code></td>
<td>
<p>Returns <code>true</code> if the value was replaced.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="setValueAt(kotlin.Int, kotlin.Any)"></a><a name="setValueAt-kotlin.Int-kotlin.Any-"></a><a name="setvalueat"></a>
<div class="api-name-block">
<div>
<h3 id="setValueAt(kotlin.Int,kotlin.Any)">setValueAt</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;void&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#setValueAt(kotlin.Int,kotlin.Any)">setValueAt</a>(int&nbsp;index,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;value)</pre>
<p>Given an index in the range <code>0...size()-1</code>, sets a new value for the <code>index</code>th key-value mapping that this <code><a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a></code> stores.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Throws</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html">kotlin.IllegalArgumentException</a></code></td>
<td>
<p>if <code><a href="/reference/androidx/collection/LongSparseArray.html#setValueAt(kotlin.Int,kotlin.Any)">index</a></code> is not in the range <code>0...size()-1</code></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="size--"></a><a name="size"></a>
<div class="api-name-block">
<div>
<h3 id="size()">size</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;int&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#size()">size</a>()</pre>
<p>Returns the number of key-value mappings that this <code><a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a></code> currently stores.</p>
</div>
<div class="api-item"><a name="toString--"></a><a name="tostring"></a>
<div class="api-name-block">
<div>
<h3 id="toString()">toString</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#toString()">toString</a>()</pre>
<p>Returns a string representation of the object.</p>
<p>This implementation composes a string by iterating over its mappings. If this map contains itself as a value, the string &quot;(this Map)&quot; will appear in its place.</p>
</div>
<div class="api-item"><a name="valueAt-kotlin.Int-"></a><a name="valueat"></a>
<div class="api-name-block">
<div>
<h3 id="valueAt(kotlin.Int)">valueAt</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> E&nbsp;<a href="/reference/androidx/collection/LongSparseArray.html#valueAt(kotlin.Int)">valueAt</a>(int&nbsp;index)</pre>
<p>Given an index in the range <code>0...size()-1</code>, returns the value from the <code>index</code>th key-value mapping that this <code><a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a></code> stores.</p>
<p>The values corresponding to indices in ascending order are guaranteed to be associated with keys in ascending order, e.g., <code>valueAt(0)</code> will return the value associated with the smallest key and <code>valueAt(size()-1)</code> will return the value associated with the largest key.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Throws</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html">kotlin.IllegalArgumentException</a></code></td>
<td>
<p>if <code><a href="/reference/androidx/collection/LongSparseArray.html#valueAt(kotlin.Int)">index</a></code> is not in the range <code>0...size()-1</code></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="list">
<h2>Extension functions</h2>
<div class="api-item"><a name="-androidx.collection.LongSparseArray-.contains-kotlin.Long-"></a><a name="contains"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.collection.LongSparseArray).contains(kotlin.Long)">LongSparseArrayKt.contains</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;boolean&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).contains(kotlin.Long)">contains</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;key<br>)</pre>
<p>Returns true if the collection contains <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).contains(kotlin.Long)">key</a></code>.</p>
</div>
<div class="api-item"><a name="-androidx.collection.LongSparseArray-.forEach-kotlin.Function2-"></a><a name="foreach"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.collection.LongSparseArray).forEach(kotlin.Function2)">LongSparseArrayKt.forEach</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;void&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).forEach(kotlin.Function2)">forEach</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function2&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/lang/Long.html">Long</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> value,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;action<br>)</pre>
<p>Performs the given <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).forEach(kotlin.Function2)">action</a></code> for each key/value entry.</p>
</div>
<div class="api-item"><a name="(androidx.collection.LongSparseArray).getOrDefault(kotlin.Long, kotlin.Any)"></a><a name="-androidx.collection.LongSparseArray-.getOrDefault-kotlin.Long-kotlin.Any-"></a><a name="getordefault"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.collection.LongSparseArray).getOrDefault(kotlin.Long,kotlin.Any)">LongSparseArrayKt.getOrDefault</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).getOrDefault(kotlin.Long,kotlin.Any)">getOrDefault</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;key,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&nbsp;defaultValue<br>)</pre>
<p>Return the value corresponding to <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).getOrDefault(kotlin.Long,kotlin.Any)">key</a></code>, or <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).getOrDefault(kotlin.Long,kotlin.Any)">defaultValue</a></code> when not present.</p>
</div>
<div class="api-item"><a name="(androidx.collection.LongSparseArray).getOrElse(kotlin.Long, kotlin.Function0)"></a><a name="-androidx.collection.LongSparseArray-.getOrElse-kotlin.Long-kotlin.Function0-"></a><a name="getorelse"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.collection.LongSparseArray).getOrElse(kotlin.Long,kotlin.Function0)">LongSparseArrayKt.getOrElse</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).getOrElse(kotlin.Long,kotlin.Function0)">getOrElse</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;key,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;defaultValue<br>)</pre>
<p>Return the value corresponding to <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).getOrElse(kotlin.Long,kotlin.Function0)">key</a></code>, or from <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).getOrElse(kotlin.Long,kotlin.Function0)">defaultValue</a></code> when not present.</p>
</div>
<div class="api-item"><a name="-androidx.collection.LongSparseArray-.getSize--"></a><a name="getsize"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.collection.LongSparseArray).getSize()">LongSparseArrayKt.getSize</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).getSize()">getSize</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver)</pre>
<p>Returns the number of key/value pairs in the collection.</p>
</div>
<div class="api-item"><a name="-androidx.collection.LongSparseArray-.isNotEmpty--"></a><a name="isnotempty"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.collection.LongSparseArray).isNotEmpty()">LongSparseArrayKt.isNotEmpty</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;boolean&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).isNotEmpty()">isNotEmpty</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver<br>)</pre>
<p>Return true when the collection contains elements.</p>
</div>
<div class="api-item"><a name="-androidx.collection.LongSparseArray-.keyIterator--"></a><a name="keyiterator"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.collection.LongSparseArray).keyIterator()">LongSparseArrayKt.keyIterator</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-long-iterator/index.html">LongIterator</a>&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).keyIterator()">keyIterator</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver<br>)</pre>
<p>Return an iterator over the collection's keys.</p>
</div>
<div class="api-item"><a name="-androidx.collection.LongSparseArray-.plus-androidx.collection.LongSparseArray-"></a><a name="plus"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.collection.LongSparseArray).plus(androidx.collection.LongSparseArray)">LongSparseArrayKt.plus</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).plus(androidx.collection.LongSparseArray)">plus</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;other<br>)</pre>
<p>Creates a new collection by adding or replacing entries from <code><a href="/reference/androidx/collection/package-summary.html#(androidx.collection.LongSparseArray).plus(androidx.collection.LongSparseArray)">other</a></code>.</p>
</div>
<div class="api-item"><a name="(androidx.collection.LongSparseArray).set(kotlin.Long, kotlin.Any)"></a><a name="-androidx.collection.LongSparseArray-.set-kotlin.Long-kotlin.Any-"></a><a name="set"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.collection.LongSparseArray).set(kotlin.Long,kotlin.Any)">LongSparseArrayKt.set</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;void&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).set(kotlin.Long,kotlin.Any)">set</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;key,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&nbsp;value<br>)</pre>
<p>Allows the use of the index operator for storing values in the collection.</p>
</div>
<div class="api-item"><a name="-androidx.collection.LongSparseArray-.valueIterator--"></a><a name="valueiterator"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.collection.LongSparseArray).valueIterator()">LongSparseArrayKt.valueIterator</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/util/Iterator.html">Iterator</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LongSparseArrayKt.html">LongSparseArrayKt</a>.<a href="/reference/androidx/collection/LongSparseArray.html#(androidx.collection.LongSparseArray).valueIterator()">valueIterator</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/collection/LongSparseArray.html">LongSparseArray</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;receiver<br>)</pre>
<p>Return an iterator over the collection's values.</p>
</div>
</div>
</body>
</html>