public static interface Map.Entry
| java.util.Map.Entry<K, V> |
|
AbstractMap.SimpleEntry<K, V>,
AbstractMap.SimpleImmutableEntry<K, V>
|
一个映射条目(键值对)。 Map.entrySet方法返回映射的集合视图,其元素属于此类。 获取对地图条目的引用的唯一方法是从该集合视图的迭代器中获取。 这些Map.Entry对象仅在迭代期间有效; 更正式地说,如果在迭代器返回条目之后,支持映射已被修改,映射条目的行为是未定义的,除非通过映射条目上的setValue操作。
也可以看看:
公共方法(Public methods) |
|
|---|---|
static <K, V> Comparator<Entry<K, V>> |
comparingByKey(Comparator<? super K> cmp) 返回一个使用给定的 |
static <K extends Comparable<? super K>, V> Comparator<Entry<K, V>> |
comparingByKey() |
static <K, V> Comparator<Entry<K, V>> |
comparingByValue(Comparator<? super V> cmp) 返回进行比较的比较 |
static <K, V extends Comparable<? super V>> Comparator<Entry<K, V>> |
comparingByValue() 返回一个比较值,该值比较 |
abstract boolean |
equals(Object o) 将指定的对象与此条目进行比较以求相等。 |
abstract K |
getKey() 返回与此条目对应的键。 |
abstract V |
getValue() 返回与此条目相对应的值。 |
abstract int |
hashCode() 返回此映射条目的哈希码值。 |
abstract V |
setValue(V value) 用指定的值替换与此条目相对应的值(可选操作)。 |
Comparator<Entry<K, V>> comparingByKey (Comparator<? super K> cmp)
返回一个使用给定的 Comparator通过键比较 Map.Entry的比较器。
如果指定的比较器也是可串行化的,则返回的比较器是可串行化的。
| 参数(Parameters) | |
|---|---|
cmp |
Comparator: the key Comparator |
| 返回(Returns) | |
|---|---|
Comparator<Entry<K, V>> |
a comparator that compares Map.Entry by the key. |
Comparator<Entry<K, V>> comparingByKey ()
返回一个比较器, Map.Entry在键上按自然顺序比较 Map.Entry 。
返回的比较器是可序列化的,并在将条目与空键进行比较时引发 NullPointerException 。
| 返回(Returns) | |
|---|---|
Comparator<Entry<K, V>> |
a comparator that compares Map.Entry in natural order on key. |
也可以看看:
Comparator<Entry<K, V>> comparingByValue (Comparator<? super V> cmp)
返回进行比较的比较 Map.Entry通过使用所述给定值 Comparator 。
如果指定的比较器也是可串行化的,则返回的比较器是可串行化的。
| 参数(Parameters) | |
|---|---|
cmp |
Comparator: the value Comparator |
| 返回(Returns) | |
|---|---|
Comparator<Entry<K, V>> |
a comparator that compares Map.Entry by the value. |
Comparator<Entry<K, V>> comparingByValue ()
返回一个比较值,该值比较 Map.Entry的自然顺序值。
返回的比较器是可串行化的,并在比较条目与空值时抛出 NullPointerException 。
| 返回(Returns) | |
|---|---|
Comparator<Entry<K, V>> |
a comparator that compares Map.Entry in natural order on value. |
也可以看看:
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 |
| 抛出异常(Throws) | |
|---|---|
IllegalStateException |
implementations may, but are not required to, throw this exception if the entry has been removed from the backing map. |
V getValue ()
返回与此条目相对应的值。 如果映射已从支持映射中删除(通过迭代器的remove操作),则此调用的结果是未定义的。
| 返回(Returns) | |
|---|---|
V |
the value corresponding to this entry |
| 抛出异常(Throws) | |
|---|---|
IllegalStateException |
implementations may, but are not required to, throw this exception if the entry has been removed from the backing map. |
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
Object.hashCode.
| 返回(Returns) | |
|---|---|
int |
the hash code value for this map entry |
V setValue (V value)
用指定的值替换与此条目相对应的值(可选操作)。 (写入地图。)如果映射已从地图中删除(通过迭代器的remove操作),则此调用的行为未定义。
| 参数(Parameters) | |
|---|---|
value |
V: new value to be stored in this entry |
| 返回(Returns) | |
|---|---|
V |
old value corresponding to the entry |
| 抛出异常(Throws) | |
|---|---|
UnsupportedOperationException |
if the put operation is not supported by the backing map |
ClassCastException |
if the class of the specified value prevents it from being stored in the backing map |
NullPointerException |
if the backing map does not permit null values, and the specified value is null |
IllegalArgumentException |
if some property of this value prevents it from being stored in the backing map |
IllegalStateException |
implementations may, but are not required to, throw this exception if the entry has been removed from the backing map. |