Added in API level 1

Entry

interface Entry<K : Any!, V : Any!>
java.util.Map.Entry

A map entry (key-value pair). The Entry may be unmodifiable, or the value may be modifiable if the optional setValue method is implemented. The Entry may be independent of any map, or it may represent an entry of the entry-set view of a map.

Instances of the Map.Entry interface may be obtained by iterating the entry-set view of a map. These instances maintain a connection to the original, backing map. This connection to the backing map is valid only for the duration of iteration over the entry-set view. During iteration of the entry-set view, if supported by the backing map, a change to a Map.Entry's value via the setValue method will be visible in the backing map. The behavior of such a Map.Entry instance is undefined outside of iteration of the map's entry-set view. It is also undefined if the backing map has been modified after the Map.Entry was returned by the iterator, except through the Map.Entry.setValue method. In particular, a change to the value of a mapping in the backing map might or might not be visible in the corresponding Map.Entry element of the entry-set view.

Summary

Public methods
open static Comparator<MutableEntry<K, V>!>

Returns a comparator that compares Map.Entry in natural order on key.

open static Comparator<MutableEntry<K, V>!>

Returns a comparator that compares Map.Entry by key using the given Comparator.

open static Comparator<MutableEntry<K, V>!>

Returns a comparator that compares Map.Entry in natural order on value.

open static Comparator<MutableEntry<K, V>!>

Returns a comparator that compares Map.Entry by value using the given Comparator.

open static MutableEntry<K, V>
copyOf(e: MutableEntry<out K, out V>)

Returns a copy of the given Map.Entry.

abstract K

Returns the key corresponding to this entry.

abstract V

Returns the value corresponding to this entry.

abstract V
setValue(value: V)

Replaces the value corresponding to this entry with the specified value (optional operation).

Public methods

comparingByKey

Added in API level 24
open static fun <K : Comparable<K>!, V : Any!> comparingByKey(): Comparator<MutableEntry<K, V>!>

Returns a comparator that compares Map.Entry in natural order on key.

The returned comparator is serializable and throws NullPointerException when comparing an entry with a null key.

Parameters
<K> the Comparable type of then map keys
<V> the type of the map values
Return
Comparator<MutableEntry<K, V>!> a comparator that compares Map.Entry in natural order on key.

comparingByKey

Added in API level 24
open static fun <K : Any!, V : Any!> comparingByKey(cmp: Comparator<in K>): Comparator<MutableEntry<K, V>!>

Returns a comparator that compares Map.Entry by key using the given Comparator.

The returned comparator is serializable if the specified comparator is also serializable.

Parameters
<K> the type of the map keys
<V> the type of the map values
cmp Comparator<in K>: the key Comparator
Return
Comparator<MutableEntry<K, V>!> a comparator that compares Map.Entry by the key.

comparingByValue

Added in API level 24
open static fun <K : Any!, V : Comparable<V>!> comparingByValue(): Comparator<MutableEntry<K, V>!>

Returns a comparator that compares Map.Entry in natural order on value.

The returned comparator is serializable and throws NullPointerException when comparing an entry with null values.

Parameters
<K> the type of the map keys
<V> the Comparable type of the map values
Return
Comparator<MutableEntry<K, V>!> a comparator that compares Map.Entry in natural order on value.

comparingByValue

Added in API level 24
open static fun <K : Any!, V : Any!> comparingByValue(cmp: Comparator<in V>): Comparator<MutableEntry<K, V>!>

Returns a comparator that compares Map.Entry by value using the given Comparator.

The returned comparator is serializable if the specified comparator is also serializable.

Parameters
<K> the type of the map keys
<V> the type of the map values
cmp Comparator<in V>: the value Comparator
Return
Comparator<MutableEntry<K, V>!> a comparator that compares Map.Entry by the value.

copyOf

open static fun <K : Any!, V : Any!> copyOf(e: MutableEntry<out K, out V>): MutableEntry<K, V>

Returns a copy of the given Map.Entry. The returned instance is not associated with any map. The returned instance has the same characteristics as instances returned by the Map::entry method.

Parameters
<K> the type of the key
<V> the type of the value
e MutableEntry<out K, out V>: the entry to be copied
Return
MutableEntry<K, V> a map entry equal to the given entry
Exceptions
java.lang.NullPointerException if e is null or if either of its key or value is null

getKey

Added in API level 1
abstract fun getKey(): K

Returns the key corresponding to this entry.

Return
K the key corresponding to this entry
Exceptions
java.lang.IllegalStateException implementations may, but are not required to, throw this exception if the entry has been removed from the backing map.

getValue

Added in API level 1
abstract fun getValue(): V

Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove operation), the results of this call are undefined.

Return
V the value corresponding to this entry
Exceptions
java.lang.IllegalStateException implementations may, but are not required to, throw this exception if the entry has been removed from the backing map.

setValue

Added in API level 1
abstract fun setValue(value: V): V

Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's remove operation).

Parameters
value V: new value to be stored in this entry
Return
V old value corresponding to the entry
Exceptions
java.lang.UnsupportedOperationException if the put operation is not supported by the backing map
java.lang.ClassCastException if the class of the specified value prevents it from being stored in the backing map
java.lang.NullPointerException if the backing map does not permit null values, and the specified value is null
java.lang.IllegalArgumentException if some property of this value prevents it from being stored in the backing map
java.lang.IllegalStateException implementations may, but are not required to, throw this exception if the entry has been removed from the backing map.