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.

An Entry maintains a connection to its underlying map if the Entry was obtained by iterating the Map.entrySet view of a map, either explicitly by using an Iterator or implicitly via the enhanced for statement. This connection to the backing map is valid only during iteration of the entry-set view. During the iteration, if supported by the backing map, a change to an Entry's value via the setValue method will be visible in the backing map. The behavior of such an Entry 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 Entry was returned by the iterator, except through the setValue method. In addition, a change to the value of a mapping in the backing map might or might not be visible in the corresponding Entry of the entry-set view.

An Entry may also be obtained from a map's entry-set view by other means, for example, using the parallelStream, stream, java.util.Set#spliterator methods, any of the java.util.Set#toArray overloads, or by copying the entry-set view into another collection. It is unspecified whether the obtained Entry instances are connected to the underlying map, whether changes to such an Entry will affect the underlying the map and vice-versa, and whether such an Entry supports the optional setValue method.

In addition, an Entry may be obtained directly from a map, for example via calls to methods directly on the NavigableMap interface. An entry thus obtained is generally not connected to the map and is an unmodifiable snapshot of the mapping as of the time of the call. Such an Entry also does not generally support the setValue method.

An Entry obtained by direct construction of the AbstractMap.SimpleEntry or AbstractMap.SimpleImmutableEntry classes or from a call to the Map.entry or Map.Entry.copyOf methods is not connected to any map.

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

Added in API level 35
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.