public static class AbstractMap.SimpleEntry
extends Object implements Entry<K, V>, Serializable
| java.lang.Object | |
| java.util.AbstractMap.SimpleEntry<K, V> | |
一个维护一个键和一个值的条目。 该值可以使用setValue方法进行更改。 这个类有助于构建自定义地图实现的过程。 例如,在方法Map.entrySet().toArray中返回SimpleEntry实例的数组可能很方便。
Public constructors |
|
|---|---|
AbstractMap.SimpleEntry(K key, V value) 创建一个表示从指定键到指定值的映射的条目。 |
|
AbstractMap.SimpleEntry(Entry<? extends K, ? extends V> entry) 创建一个表示与指定条目相同映射的条目。 |
|
公共方法(Public methods) |
|
|---|---|
boolean |
equals(Object o) 将指定的对象与此条目进行比较以求相等。 |
K |
getKey() 返回与此条目对应的键。 |
V |
getValue() 返回与此条目相对应的值。 |
int |
hashCode() 返回此映射条目的哈希码值。 |
V |
setValue(V value) 用指定的值替换此条目对应的值。 |
String |
toString() 返回此映射条目的字符串表示形式。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
java.util.Map.Entry
|
|
AbstractMap.SimpleEntry (K key,
V value)
创建一个表示从指定键到指定值的映射的条目。
| 参数(Parameters) | |
|---|---|
key |
K: the key represented by this entry |
value |
V: the value represented by this entry |
AbstractMap.SimpleEntry (Entry<? extends K, ? extends V> entry)
创建一个表示与指定条目相同映射的条目。
| 参数(Parameters) | |
|---|---|
entry |
Entry: the entry to copy |
boolean equals (Object o)
将指定的对象与此条目进行比较以求相等。 如果给定对象也是一个映射条目并且两个条目表示相同的映射,则返回true 。 更正式地,如果两个条目e1和e2表示相同的映射
(e1.getKey()==null ?
e2.getKey()==null :
e1.getKey().equals(e2.getKey()))
&&
(e1.getValue()==null ?
e2.getValue()==null :
e1.getValue().equals(e2.getValue())) This ensures that the
equals method works properly across different implementations of the
Map.Entry interface.
| 参数(Parameters) | |
|---|---|
o |
Object: object to be compared for equality with this map entry |
| 返回(Returns) | |
|---|---|
boolean |
true if the specified object is equal to this map entry |
也可以看看:
K getKey ()
返回与此条目对应的键。
| 返回(Returns) | |
|---|---|
K |
the key corresponding to this entry |
V getValue ()
返回与此条目相对应的值。
| 返回(Returns) | |
|---|---|
V |
the value corresponding to this entry |
int hashCode ()
返回此映射条目的哈希码值。 映射条目e的哈希码被定义为:
(e.getKey()==null ? 0 : e.getKey().hashCode()) ^ (e.getValue()==null ? 0 : e.getValue().hashCode())This ensures that
e1.equals(e2) implies that
e1.hashCode()==e2.hashCode() for any two Entries
e1 and
e2, as required by the general contract of
hashCode().
| 返回(Returns) | |
|---|---|
int |
the hash code value for this map entry |
也可以看看:
V setValue (V value)
用指定的值替换此条目对应的值。
| 参数(Parameters) | |
|---|---|
value |
V: new value to be stored in this entry |
| 返回(Returns) | |
|---|---|
V |
the old value corresponding to the entry |
String toString ()
返回此映射条目的字符串表示形式。 此实现返回此条目的键的字符串表示形式,后跟等号字符(“ = ”),后跟此条目值的字符串表示形式。
| 返回(Returns) | |
|---|---|
String |
a String representation of this map entry |