Google is committed to advancing racial equity for Black communities. See how.
Added in API level 1

Entry

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

A map entry (key-value pair). The Map.entrySet method returns a collection-view of the map, whose elements are of this class. The only way to obtain a reference to a map entry is from the iterator of this collection-view. These Map.Entry objects are valid only for the duration of the iteration; more formally, the behavior of a map entry is undefined if the backing map has been modified after the entry was returned by the iterator, except through the setValue operation on the map entry.

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.

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.

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.