SimpleEntry
open class SimpleEntry<K : Any!, V : Any!> : MutableEntry<K, V>, Serializable
| kotlin.Any | |
| ↳ | java.util.AbstractMap.SimpleEntry |
An Entry maintaining a key and a value. The value may be changed using the setValue method. Instances of this class are not associated with any map nor with any map's entry-set view.
Summary
| Public constructors | |
|---|---|
SimpleEntry(entry: MutableEntry<out K, out V>)Creates an entry representing the same mapping as the specified entry. |
|
SimpleEntry(key: K, value: V)Creates an entry representing a mapping from the specified key to the specified value. |
|
| Public methods | |
|---|---|
| open Boolean |
Compares the specified object with this entry for equality. |
| open Int |
hashCode()Returns the hash code value for this map entry. |
| open V |
setValue(newValue: V)Replaces the value corresponding to this entry with the specified value. |
| open String |
toString()Returns a String representation of this map entry. |
| Properties | |
|---|---|
| open K |
Returns the key corresponding to this entry. |
| open V |
Returns the value corresponding to this entry. |
Public constructors
SimpleEntry
SimpleEntry(entry: MutableEntry<out K, out V>)
Creates an entry representing the same mapping as the specified entry.
| Parameters | |
|---|---|
entry |
MutableEntry<out K, out V>: the entry to copy |
SimpleEntry
SimpleEntry(
key: K,
value: V)
Creates an entry representing a mapping from the specified key to the specified value.
| Parameters | |
|---|---|
key |
K: the key represented by this entry |
value |
V: the value represented by this entry |
Public methods
equals
open fun equals(other: Any?): Boolean
Compares the specified object with this entry for equality. Returns true if the given object is also a map entry and the two entries represent the same mapping. More formally, two entries e1 and e2 represent the same mapping if
(e1.getKey()==null ? e2.getKey()==null : e1.getKey().equals(e2.getKey())) && (e1.getValue()==null ? e2.getValue()==null : e1.getValue().equals(e2.getValue()))
equals method works properly across different implementations of the Map.Entry interface.
| Parameters | |
|---|---|
obj |
the reference object with which to compare. |
o |
object to be compared for equality with this map entry |
| Return | |
|---|---|
Boolean |
true if the specified object is equal to this map entry |
See Also
hashCode
open fun hashCode(): Int
Returns the hash code value for this map entry. The hash code of a map entry e is defined to be:
(e.getKey()==null ? 0 : e.getKey().hashCode()) ^ (e.getValue()==null ? 0 : e.getValue().hashCode())
e1.equals(e2) implies that e1.hashCode()==e2.hashCode() for any two Entries e1 and e2, as required by the general contract of Object.hashCode.
| Return | |
|---|---|
Int |
the hash code value for this map entry |
See Also
setValue
open fun setValue(newValue: V): V
Replaces the value corresponding to this entry with the specified value.
| Parameters | |
|---|---|
value |
new value to be stored in this entry |
| Return | |
|---|---|
V |
the 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. |
toString
open fun toString(): String
Returns a String representation of this map entry. This implementation returns the string representation of this entry's key followed by the equals character ("=") followed by the string representation of this entry's value.
| Return | |
|---|---|
String |
a String representation of this map entry |
Properties
key
open val key: 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. |
value
open val value: V
Returns the value corresponding to this entry.
| 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. |