Added in API level 9

ConcurrentSkipListMap

open class ConcurrentSkipListMap<K : Any!, V : Any!> : AbstractMap<K, V>, ConcurrentNavigableMap<K, V>, Cloneable, Serializable, MutableMap<K, V>
kotlin.Any
   ↳ java.util.AbstractMap<K, V>
   ↳ java.util.concurrent.ConcurrentSkipListMap

A scalable concurrent ConcurrentNavigableMap implementation. The map is sorted according to the ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.

This class implements a concurrent variant of SkipLists providing expected average log(n) time cost for the containsKey, get, put and remove operations and their variants. Insertion, removal, update, and access operations safely execute concurrently by multiple threads.

Iterators and spliterators are weakly consistent.

Ascending key ordered views and their iterators are faster than descending ones.

All Map.Entry pairs returned by methods in this class and its views represent snapshots of mappings at the time they were produced. They do not support the Entry.setValue method. (Note however that it is possible to change mappings in the associated map using put, putIfAbsent, or replace, depending on exactly which effect you need.)

Beware that bulk operations putAll, equals, toArray, containsValue, and clear are not guaranteed to be performed atomically. For example, an iterator operating concurrently with a putAll operation might view only some of the added elements.

This class and its views and iterators implement all of the optional methods of the Map and Iterator interfaces. Like most other concurrent collections, this class does not permit the use of null keys or values because some null return values cannot be reliably distinguished from the absence of elements.

This class is a member of the Java Collections Framework.

Summary

Public constructors

Constructs a new, empty map, sorted according to the natural ordering of the keys.

ConcurrentSkipListMap(comparator: Comparator<in K>!)

Constructs a new, empty map, sorted according to the specified comparator.

ConcurrentSkipListMap(m: MutableMap<out K, out V>!)

Constructs a new map containing the same mappings as the given map, sorted according to the natural ordering of the keys.

Constructs a new map containing the same mappings and using the same ordering as the specified sorted map.

Public methods
open MutableEntry<K, V>?
ceilingEntry(key: K)

Returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such entry.

open K?
ceilingKey(key: K)

open Unit

Removes all of the mappings from this map.

open ConcurrentSkipListMap<K, V>

Returns a shallow copy of this ConcurrentSkipListMap instance.

open Comparator<in K>?

open V?
compute(key: K, remappingFunction: BiFunction<in K, in V?, out V?>)

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).

open V
computeIfAbsent(key: K, mappingFunction: Function<in K, out V>)

If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unless null.

open V?
computeIfPresent(key: K, remappingFunction: BiFunction<in K, in V, out V?>)

If the value for the specified key is present, attempts to compute a new mapping given the key and its current mapped value.

open Boolean
containsKey(key: K)

Returns true if this map contains a mapping for the specified key.

open Boolean
containsKey(key: K)

Returns true if this map contains a mapping for the specified key.

open Boolean
containsValue(value: V)

Returns true if this map maps one or more keys to the specified value.

open Boolean
containsValue(value: V)

Returns true if this map maps one or more keys to the specified value.

open NavigableSet<K>

open ConcurrentNavigableMap<K, V>

open Boolean
equals(other: Any?)

Compares the specified object with this map for equality.

open MutableEntry<K, V>?

Returns a key-value mapping associated with the least key in this map, or null if the map is empty.

open K

open MutableEntry<K, V>?
floorEntry(key: K)

Returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.

open K?
floorKey(key: K)

open Unit
forEach(action: BiConsumer<in K, in V>)

open V?
get(key: K)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

open V?
get(key: K)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

open V
getOrDefault(key: K, defaultValue: V)

Returns the value to which the specified key is mapped, or the given defaultValue if this map contains no mapping for the key.

open ConcurrentNavigableMap<K, V>
headMap(toKey: K, inclusive: Boolean)

open ConcurrentNavigableMap<K, V>
headMap(toKey: K)

open MutableEntry<K, V>?
higherEntry(key: K)

Returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key.

open K?
higherKey(key: K)

open Boolean

Returns true if this map contains no key-value mappings.

open MutableEntry<K, V>?

Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.

open K

open MutableEntry<K, V>?
lowerEntry(key: K)

Returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key.

open K?
lowerKey(key: K)

open V?
merge(key: K, value: V, remappingFunction: BiFunction<in V, in V, out V?>)

If the specified key is not already associated with a value, associates it with the given value.

open NavigableSet<K>

open MutableEntry<K, V>?

Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty.

open MutableEntry<K, V>?

Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.

open V?
put(key: K, value: V)

Associates the specified value with the specified key in this map.

open V?
putFirst(k: K, v: V)

Throws UnsupportedOperationException.

open V?
putIfAbsent(key: K, value: V)

If the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value.

open V?
putLast(k: K, v: V)

Throws UnsupportedOperationException.

open V?
remove(key: K)

Removes the mapping for the specified key from this map if present.

open Boolean
remove(key: K, value: V)

Removes the entry for the specified key only if it is currently mapped to the specified value.

open V?
remove(key: K)

Removes the mapping for the specified key from this map if present.

open Boolean
replace(key: K, oldValue: V, newValue: V)

Replaces the entry for the specified key only if currently mapped to the specified value.

open V?
replace(key: K, value: V)

Replaces the entry for the specified key only if it is currently mapped to some value.

open Unit
replaceAll(function: BiFunction<in K, in V, out V>)

open ConcurrentNavigableMap<K, V>
subMap(fromKey: K, fromInclusive: Boolean, toKey: K, toInclusive: Boolean)

open ConcurrentNavigableMap<K, V>
subMap(fromKey: K, toKey: K)

open ConcurrentNavigableMap<K, V>
tailMap(fromKey: K, inclusive: Boolean)

open ConcurrentNavigableMap<K, V>
tailMap(fromKey: K)

Inherited functions
Properties
open MutableSet<MutableEntry<K, V>>

Returns a Set view of the mappings contained in this map.

open NavigableSet<K>

Returns a NavigableSet view of the keys contained in this map.

open Int

Returns the number of key-value mappings in this map.

open MutableCollection<V>

Returns a Collection view of the values contained in this map.

Public constructors

ConcurrentSkipListMap

Added in API level 9
ConcurrentSkipListMap()

Constructs a new, empty map, sorted according to the natural ordering of the keys.

ConcurrentSkipListMap

Added in API level 9
ConcurrentSkipListMap(comparator: Comparator<in K>!)

Constructs a new, empty map, sorted according to the specified comparator.

Parameters
comparator Comparator<in K>!: the comparator that will be used to order this map. If null, the ordering of the keys will be used.

ConcurrentSkipListMap

Added in API level 9
ConcurrentSkipListMap(m: MutableMap<out K, out V>!)

Constructs a new map containing the same mappings as the given map, sorted according to the natural ordering of the keys.

Parameters
m MutableMap<out K, out V>!: the map whose mappings are to be placed in this map
Exceptions
java.lang.ClassCastException if the keys in m are not Comparable, or are not mutually comparable
java.lang.NullPointerException if the specified map or any of its keys or values are null

ConcurrentSkipListMap

Added in API level 9
ConcurrentSkipListMap(m: SortedMap<K, out V>!)

Constructs a new map containing the same mappings and using the same ordering as the specified sorted map.

Parameters
m SortedMap<K, out V>!: the sorted map whose mappings are to be placed in this map, and whose comparator is to be used to sort this map
Exceptions
java.lang.NullPointerException if the specified sorted map or any of its keys or values are null

Public methods

ceilingEntry

Added in API level 9
open fun ceilingEntry(key: K): MutableEntry<K, V>?

Returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such entry. The returned entry does not support the Entry.setValue method.

Parameters
key K: the key
Return
MutableEntry<K, V>? an entry with the least key greater than or equal to key, or null if there is no such key
Exceptions
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

ceilingKey

Added in API level 9
open fun ceilingKey(key: K): K?
Parameters
key K: the key
Return
K? the least key greater than or equal to key, or null if there is no such key
Exceptions
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

clear

Added in API level 9
open fun clear(): Unit

Removes all of the mappings from this map.

Exceptions
java.lang.UnsupportedOperationException if the clear operation is not supported by this map

clone

Added in API level 9
open fun clone(): ConcurrentSkipListMap<K, V>

Returns a shallow copy of this ConcurrentSkipListMap instance. (The keys and values themselves are not cloned.)

Return
ConcurrentSkipListMap<K, V> a shallow copy of this map
Exceptions
java.lang.CloneNotSupportedException if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.

comparator

Added in API level 9
open fun comparator(): Comparator<in K>?
Return
Comparator<in K>? the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys

compute

Added in API level 24
open fun compute(
    key: K,
    remappingFunction: BiFunction<in K, in V?, out V?>
): V?

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). The function is NOT guaranteed to be applied once atomically.

Parameters
key K: key with which the specified value is to be associated
remappingFunction BiFunction<in K, in V?, out V?>: the function to compute a value
Return
V? the new value associated with the specified key, or null if none
Exceptions
java.lang.NullPointerException if the specified key is null or the remappingFunction is null
java.lang.UnsupportedOperationException if the put operation is not supported by this map (optional)
java.lang.ClassCastException if the class of the specified key or value prevents it from being stored in this map (optional)
java.lang.IllegalArgumentException if some property of the specified key or value prevents it from being stored in this map (optional)

computeIfAbsent

Added in API level 24
open fun computeIfAbsent(
    key: K,
    mappingFunction: Function<in K, out V>
): V

If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unless null. The function is NOT guaranteed to be applied once atomically only if the value is not present.

Parameters
key K: key with which the specified value is to be associated
mappingFunction Function<in K, out V>: the function to compute a value
Return
V the current (existing or computed) value associated with the specified key, or null if the computed value is null
Exceptions
java.lang.NullPointerException if the specified key is null or the mappingFunction is null
java.lang.UnsupportedOperationException if the put operation is not supported by this map (optional)
java.lang.ClassCastException if the class of the specified key or value prevents it from being stored in this map (optional)
java.lang.IllegalArgumentException if some property of the specified key or value prevents it from being stored in this map (optional)

computeIfPresent

Added in API level 24
open fun computeIfPresent(
    key: K,
    remappingFunction: BiFunction<in K, in V, out V?>
): V?

If the value for the specified key is present, attempts to compute a new mapping given the key and its current mapped value. The function is NOT guaranteed to be applied once atomically.

Parameters
key K: key with which a value may be associated
remappingFunction BiFunction<in K, in V, out V?>: the function to compute a value
Return
V? the new value associated with the specified key, or null if none
Exceptions
java.lang.NullPointerException if the specified key is null or the remappingFunction is null
java.lang.UnsupportedOperationException if the put operation is not supported by this map (optional)
java.lang.ClassCastException if the class of the specified key or value prevents it from being stored in this map (optional)
java.lang.IllegalArgumentException if some property of the specified key or value prevents it from being stored in this map (optional)

containsKey

Added in API level 9
open fun containsKey(key: K): Boolean

Returns true if this map contains a mapping for the specified key.

Parameters
key K: key whose presence in this map is to be tested
Return
Boolean true if this map contains a mapping for the specified key
Exceptions
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

containsKey

Added in API level 9
open fun containsKey(key: K): Boolean

Returns true if this map contains a mapping for the specified key.

Parameters
key K: key whose presence in this map is to be tested
Return
Boolean true if this map contains a mapping for the specified key
Exceptions
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

containsValue

Added in API level 9
open fun containsValue(value: V): Boolean

Returns true if this map maps one or more keys to the specified value. This operation requires time linear in the map size. Additionally, it is possible for the map to change during execution of this method, in which case the returned result may be inaccurate.

Parameters
value V: value whose presence in this map is to be tested
Return
Boolean true if a mapping to value exists; false otherwise
Exceptions
java.lang.ClassCastException if the value is of an inappropriate type for this map (optional)
java.lang.NullPointerException if the specified value is null

containsValue

Added in API level 9
open fun containsValue(value: V): Boolean

Returns true if this map maps one or more keys to the specified value. This operation requires time linear in the map size. Additionally, it is possible for the map to change during execution of this method, in which case the returned result may be inaccurate.

Parameters
value V: value whose presence in this map is to be tested
Return
Boolean true if a mapping to value exists; false otherwise
Exceptions
java.lang.ClassCastException if the value is of an inappropriate type for this map (optional)
java.lang.NullPointerException if the specified value is null

descendingKeySet

Added in API level 9
open fun descendingKeySet(): NavigableSet<K>
Return
NavigableSet<K> a reverse order navigable set view of the keys in this map

descendingMap

Added in API level 9
open fun descendingMap(): ConcurrentNavigableMap<K, V>
Return
ConcurrentNavigableMap<K, V> a reverse order view of this map

equals

Added in API level 9
open fun equals(other: Any?): Boolean

Compares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent the same mappings. More formally, two maps m1 and m2 represent the same mappings if m1.entrySet().equals(m2.entrySet()). This operation may return misleading results if either map is concurrently modified during execution of this method.

Parameters
obj the reference object with which to compare.
o object to be compared for equality with this map
Return
Boolean true if the specified object is equal to this map

firstEntry

Added in API level 9
open fun firstEntry(): MutableEntry<K, V>?

Returns a key-value mapping associated with the least key in this map, or null if the map is empty. The returned entry does not support the Entry.setValue method.

Return
MutableEntry<K, V>? an entry with the least key, or null if this map is empty

firstKey

Added in API level 9
open fun firstKey(): K
Return
K the first (lowest) key currently in this map
Exceptions
java.util.NoSuchElementException if this map is empty

floorEntry

Added in API level 9
open fun floorEntry(key: K): MutableEntry<K, V>?

Returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key. The returned entry does not support the Entry.setValue method.

Parameters
key K: the key
Return
MutableEntry<K, V>? an entry with the greatest key less than or equal to key, or null if there is no such key
Exceptions
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

floorKey

Added in API level 9
open fun floorKey(key: K): K?
Parameters
key K: the key
Return
K? the greatest key less than or equal to key, or null if there is no such key
Exceptions
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

forEach

Added in API level 24
open fun forEach(action: BiConsumer<in K, in V>): Unit
Parameters
action BiConsumer<in K, in V>: The action to be performed for each entry
Exceptions
java.lang.NullPointerException if the specified action is null
java.util.ConcurrentModificationException if an entry is found to be removed during iteration

get

Added in API level 9
open fun get(key: K): V?

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that key compares equal to k according to the map's ordering, then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

Parameters
key K: the key whose associated value is to be returned
Return
V? the value to which the specified key is mapped, or null if this map contains no mapping for the key
Exceptions
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

get

Added in API level 9
open fun get(key: K): V?

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that key compares equal to k according to the map's ordering, then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

Parameters
key K: the key whose associated value is to be returned
Return
V? the value to which the specified key is mapped, or null if this map contains no mapping for the key
Exceptions
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

getOrDefault

Added in API level 24
open fun getOrDefault(
    key: K,
    defaultValue: V
): V

Returns the value to which the specified key is mapped, or the given defaultValue if this map contains no mapping for the key.

Parameters
key K: the key
defaultValue V: the value to return if this map contains no mapping for the given key
Return
V the mapping for the key, if present; else the defaultValue
Exceptions
java.lang.ClassCastException if the key is of an inappropriate type for this map (optional)
java.lang.NullPointerException if the specified key is null

headMap

Added in API level 9
open fun headMap(
    toKey: K,
    inclusive: Boolean
): ConcurrentNavigableMap<K, V>
Parameters
toKey K: high endpoint of the keys in the returned map
inclusive Boolean: true if the high endpoint is to be included in the returned view
Return
ConcurrentNavigableMap<K, V> a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey
Exceptions
java.lang.ClassCastException if toKey is not compatible with this map's comparator (or, if the map has no comparator, if toKey does not implement Comparable). Implementations may, but are not required to, throw this exception if toKey cannot be compared to keys currently in the map.
java.lang.NullPointerException if toKey is null
java.lang.IllegalArgumentException if this map itself has a restricted range, and toKey lies outside the bounds of the range

headMap

Added in API level 9
open fun headMap(toKey: K): ConcurrentNavigableMap<K, V>
Parameters
toKey K: high endpoint (exclusive) of the keys in the returned map
Return
ConcurrentNavigableMap<K, V> a view of the portion of this map whose keys are strictly less than toKey
Exceptions
java.lang.ClassCastException if toKey is not compatible with this map's comparator (or, if the map has no comparator, if toKey does not implement Comparable). Implementations may, but are not required to, throw this exception if toKey cannot be compared to keys currently in the map.
java.lang.NullPointerException if toKey is null
java.lang.IllegalArgumentException if this map itself has a restricted range, and toKey lies outside the bounds of the range

higherEntry

Added in API level 9
open fun higherEntry(key: K): MutableEntry<K, V>?

Returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key. The returned entry does not support the Entry.setValue method.

Parameters
key K: the key
Return
MutableEntry<K, V>? an entry with the least key greater than key, or null if there is no such key
Exceptions
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

higherKey

Added in API level 9
open fun higherKey(key: K): K?
Parameters
key K: the key
Return
K? the least key greater than key, or null if there is no such key
Exceptions
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

isEmpty

Added in API level 9
open fun isEmpty(): Boolean

Returns true if this map contains no key-value mappings.

Return
Boolean true if this map contains no key-value mappings

lastEntry

Added in API level 9
open fun lastEntry(): MutableEntry<K, V>?

Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty. The returned entry does not support the Entry.setValue method.

Return
MutableEntry<K, V>? an entry with the greatest key, or null if this map is empty

lastKey

Added in API level 9
open fun lastKey(): K
Return
K the last (highest) key currently in this map
Exceptions
java.util.NoSuchElementException if this map is empty

lowerEntry

Added in API level 9
open fun lowerEntry(key: K): MutableEntry<K, V>?

Returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key. The returned entry does not support the Entry.setValue method.

Parameters
key K: the key
Return
MutableEntry<K, V>? an entry with the greatest key less than key, or null if there is no such key
Exceptions
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

lowerKey

Added in API level 9
open fun lowerKey(key: K): K?
Parameters
key K: the key
Return
K? the greatest key less than key, or null if there is no such key
Exceptions
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

merge

Added in API level 24
open fun merge(
    key: K,
    value: V,
    remappingFunction: BiFunction<in V, in V, out V?>
): V?

If the specified key is not already associated with a value, associates it with the given value. Otherwise, replaces the value with the results of the given remapping function, or removes if null. The function is NOT guaranteed to be applied once atomically.

Parameters
key K: key with which the specified value is to be associated
value V: the value to use if absent
remappingFunction BiFunction<in V, in V, out V?>: the function to recompute a value if present
Return
V? the new value associated with the specified key, or null if none
Exceptions
java.lang.UnsupportedOperationException if the put operation is not supported by this map (optional)
java.lang.ClassCastException if the class of the specified key or value prevents it from being stored in this map (optional)
java.lang.IllegalArgumentException if some property of the specified key or value prevents it from being stored in this map (optional)
java.lang.NullPointerException if the specified key or value is null or the remappingFunction is null
Added in API level 9
open fun navigableKeySet(): NavigableSet<K>
Return
NavigableSet<K> a navigable set view of the keys in this map

pollFirstEntry

Added in API level 9
open fun pollFirstEntry(): MutableEntry<K, V>?

Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty. The returned entry does not support the Entry.setValue method.

Return
MutableEntry<K, V>? the removed first entry of this map, or null if this map is empty
Exceptions
java.lang.UnsupportedOperationException if this collection implementation does not support this operation

pollLastEntry

Added in API level 9
open fun pollLastEntry(): MutableEntry<K, V>?

Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty. The returned entry does not support the Entry.setValue method.

Return
MutableEntry<K, V>? the removed last entry of this map, or null if this map is empty
Exceptions
java.lang.UnsupportedOperationException if this collection implementation does not support this operation

put

Added in API level 9
open fun put(
    key: K,
    value: V
): V?

Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.

Parameters
key K: key with which the specified value is to be associated
value V: value to be associated with the specified key
Return
V? the previous value associated with the specified key, or null if there was no mapping for the key
Exceptions
java.lang.UnsupportedOperationException if the put operation is not supported by this map
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key or value is null
java.lang.IllegalArgumentException if some property of the specified key or value prevents it from being stored in this map

putFirst

open fun putFirst(
    k: K,
    v: V
): V?

Throws UnsupportedOperationException. The encounter order induced by this map's comparison method determines the position of mappings, so explicit positioning is not supported.

Parameters
k K: the key
v V: the value
Return
V? the value previously associated with k, or null if none
Exceptions
java.lang.UnsupportedOperationException always

putIfAbsent

Added in API level 9
open fun putIfAbsent(
    key: K,
    value: V
): V?

If the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value.

Parameters
key K: key with which the specified value is to be associated
value V: value to be associated with the specified key
Return
V? the previous value associated with the specified key, or null if there was no mapping for the key
Exceptions
java.lang.UnsupportedOperationException if the put operation is not supported by this map
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key or value is null
java.lang.IllegalArgumentException if some property of the specified key or value prevents it from being stored in this map

putLast

open fun putLast(
    k: K,
    v: V
): V?

Throws UnsupportedOperationException. The encounter order induced by this map's comparison method determines the position of mappings, so explicit positioning is not supported.

Parameters
k K: the key
v V: the value
Return
V? the value previously associated with k, or null if none
Exceptions
java.lang.UnsupportedOperationException always

remove

Added in API level 9
open fun remove(key: K): V?

Removes the mapping for the specified key from this map if present.

Parameters
key K: key for which mapping should be removed
Return
V? the previous value associated with the specified key, or null if there was no mapping for the key
Exceptions
java.lang.UnsupportedOperationException if the remove operation is not supported by this map
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

remove

Added in API level 9
open fun remove(
    key: K,
    value: V
): Boolean

Removes the entry for the specified key only if it is currently mapped to the specified value.

Parameters
key K: key with which the specified value is associated
value V: value expected to be associated with the specified key
Return
Boolean true if the value was removed
Exceptions
java.lang.UnsupportedOperationException if the remove operation is not supported by this map
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

remove

Added in API level 9
open fun remove(key: K): V?

Removes the mapping for the specified key from this map if present.

Parameters
key K: key for which mapping should be removed
Return
V? the previous value associated with the specified key, or null if there was no mapping for the key
Exceptions
java.lang.UnsupportedOperationException if the remove operation is not supported by this map
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key is null

replace

Added in API level 9
open fun replace(
    key: K,
    oldValue: V,
    newValue: V
): Boolean

Replaces the entry for the specified key only if currently mapped to the specified value.

Parameters
key K: key with which the specified value is associated
oldValue V: value expected to be associated with the specified key
newValue V: value to be associated with the specified key
Return
Boolean true if the value was replaced
Exceptions
java.lang.UnsupportedOperationException if the put operation is not supported by this map
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if any of the arguments are null
java.lang.IllegalArgumentException if some property of a specified key or value prevents it from being stored in this map

replace

Added in API level 9
open fun replace(
    key: K,
    value: V
): V?

Replaces the entry for the specified key only if it is currently mapped to some value.

Parameters
key K: key with which the specified value is associated
value V: value to be associated with the specified key
Return
V? the previous value associated with the specified key, or null if there was no mapping for the key
Exceptions
java.lang.UnsupportedOperationException if the put operation is not supported by this map
java.lang.ClassCastException if the specified key cannot be compared with the keys currently in the map
java.lang.NullPointerException if the specified key or value is null
java.lang.IllegalArgumentException if some property of the specified key or value prevents it from being stored in this map

replaceAll

Added in API level 24
open fun replaceAll(function: BiFunction<in K, in V, out V>): Unit
Parameters
function BiFunction<in K, in V, out V>: the function to apply to each entry
Exceptions
java.lang.UnsupportedOperationException if the set operation is not supported by this map's entry set iterator.
java.lang.ClassCastException if the class of a replacement value prevents it from being stored in this map
java.lang.NullPointerException if the specified function is null, or the specified replacement value is null, and this map does not permit null values
java.lang.IllegalArgumentException if some property of a replacement value prevents it from being stored in this map (optional)
java.util.ConcurrentModificationException if an entry is found to be removed during iteration

subMap

Added in API level 9
open fun subMap(
    fromKey: K,
    fromInclusive: Boolean,
    toKey: K,
    toInclusive: Boolean
): ConcurrentNavigableMap<K, V>
Parameters
fromKey K: low endpoint of the keys in the returned map
fromInclusive Boolean: true if the low endpoint is to be included in the returned view
toKey K: high endpoint of the keys in the returned map
toInclusive Boolean: true if the high endpoint is to be included in the returned view
Return
ConcurrentNavigableMap<K, V> a view of the portion of this map whose keys range from fromKey to toKey
Exceptions
java.lang.ClassCastException if fromKey and toKey cannot be compared to one another using this map's comparator (or, if the map has no comparator, using natural ordering). Implementations may, but are not required to, throw this exception if fromKey or toKey cannot be compared to keys currently in the map.
java.lang.NullPointerException if fromKey or toKey is null
java.lang.IllegalArgumentException if fromKey is greater than toKey; or if this map itself has a restricted range, and fromKey or toKey lies outside the bounds of the range

subMap

Added in API level 9
open fun subMap(
    fromKey: K,
    toKey: K
): ConcurrentNavigableMap<K, V>
Parameters
fromKey K: low endpoint (inclusive) of the keys in the returned map
toKey K: high endpoint (exclusive) of the keys in the returned map
Return
ConcurrentNavigableMap<K, V> a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive
Exceptions
java.lang.ClassCastException if fromKey and toKey cannot be compared to one another using this map's comparator (or, if the map has no comparator, using natural ordering). Implementations may, but are not required to, throw this exception if fromKey or toKey cannot be compared to keys currently in the map.
java.lang.NullPointerException if fromKey or toKey is null
java.lang.IllegalArgumentException if fromKey is greater than toKey; or if this map itself has a restricted range, and fromKey or toKey lies outside the bounds of the range

tailMap

Added in API level 9
open fun tailMap(
    fromKey: K,
    inclusive: Boolean
): ConcurrentNavigableMap<K, V>
Parameters
fromKey K: low endpoint of the keys in the returned map
inclusive Boolean: true if the low endpoint is to be included in the returned view
Return
ConcurrentNavigableMap<K, V> a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey
Exceptions
java.lang.ClassCastException if fromKey is not compatible with this map's comparator (or, if the map has no comparator, if fromKey does not implement Comparable). Implementations may, but are not required to, throw this exception if fromKey cannot be compared to keys currently in the map.
java.lang.NullPointerException if fromKey is null
java.lang.IllegalArgumentException if this map itself has a restricted range, and fromKey lies outside the bounds of the range

tailMap

Added in API level 9
open fun tailMap(fromKey: K): ConcurrentNavigableMap<K, V>
Parameters
fromKey K: low endpoint (inclusive) of the keys in the returned map
Return
ConcurrentNavigableMap<K, V> a view of the portion of this map whose keys are greater than or equal to fromKey
Exceptions
java.lang.ClassCastException if fromKey is not compatible with this map's comparator (or, if the map has no comparator, if fromKey does not implement Comparable). Implementations may, but are not required to, throw this exception if fromKey cannot be compared to keys currently in the map.
java.lang.NullPointerException if fromKey is null
java.lang.IllegalArgumentException if this map itself has a restricted range, and fromKey lies outside the bounds of the range

Properties

entries

Added in API level 9
open val entries: MutableSet<MutableEntry<K, V>>

Returns a Set view of the mappings contained in this map.

The set's iterator returns the entries in ascending key order. The set's spliterator additionally reports Spliterator#CONCURRENT, Spliterator#NONNULL, Spliterator#SORTED and Spliterator#ORDERED, with an encounter order that is ascending key order.

The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

The view's iterators and spliterators are weakly consistent.

The Map.Entry elements traversed by the iterator or spliterator do not support the setValue operation.

Return
MutableSet<MutableEntry<K, V>> a set view of the mappings contained in this map, sorted in ascending key order

keys

Added in API level 9
open val keys: NavigableSet<K>

Returns a NavigableSet view of the keys contained in this map.

The set's iterator returns the keys in ascending order. The set's spliterator additionally reports Spliterator#CONCURRENT, Spliterator#NONNULL, Spliterator#SORTED and Spliterator#ORDERED, with an encounter order that is ascending key order.

The spliterator's comparator is null if the map's comparator is null. Otherwise, the spliterator's comparator is the same as or imposes the same total ordering as the map's comparator.

The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

The view's iterators and spliterators are weakly consistent.

This method is equivalent to method navigableKeySet.

Return
NavigableSet<K> a navigable set view of the keys in this map

size

Added in API level 9
open val size: Int

Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Return
Int the number of key-value mappings in this map

values

Added in API level 9
open val values: MutableCollection<V>

Returns a Collection view of the values contained in this map.

The collection's iterator returns the values in ascending order of the corresponding keys. The collections's spliterator additionally reports Spliterator#CONCURRENT, Spliterator#NONNULL and Spliterator#ORDERED, with an encounter order that is ascending order of the corresponding keys.

The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

The view's iterators and spliterators are weakly consistent.

Return
MutableCollection<V> a collection view of the values contained in this map, sorted in ascending key order