public static interface Map.Entry<K,V>
Map.entrySet()
| Modifier and Type | Method and Description |
|---|---|
static <K extends Comparable<? super K>,V> |
comparingByKey()
|
static <K,V> Comparator<Map.Entry<K,V>> |
comparingByKey(Comparator<? super K> cmp)
返回一个比较器,比较 Map.Entry按键使用给定的Comparator 。
|
static <K,V extends Comparable<? super V>> |
comparingByValue()
返回一个比较器,比较 Map.Entry的自然顺序值。
|
static <K,V> Comparator<Map.Entry<K,V>> |
comparingByValue(Comparator<? super V> cmp)
返回一个比较器 ,使用给定的 Comparator比较Map.Entry的值。
|
boolean |
equals(Object o)
将指定的对象与此条目进行比较以获得相等性。
|
K |
getKey()
返回与此条目相对应的键。
|
V |
getValue()
返回与此条目相对应的值。
|
int |
hashCode()
返回此映射条目的哈希码值。
|
V |
setValue(V value)
用指定的值替换与该条目相对应的值(可选操作)。
|
K getKey()
IllegalStateException - 如果条目已从后备映射中删除,则实现可能但不是必须抛出此异常。
V getValue()
IllegalStateException - 如果条目已从背景地图中删除,则实现可能但不是必须抛出此异常。
V setValue(V value)
value - 要存储在此条目中的新值
UnsupportedOperationException -如果
put操作不受底层映射支持
ClassCastException - 如果指定值的类阻止它存储在后台映射中
NullPointerException - 如果后台映射不允许空值,并且指定的值为空
IllegalArgumentException - 如果此值的某些属性阻止其存储在后备映射中
IllegalStateException - 如果条目已从后备映射中删除,则实现可能但不是必须抛出此异常。
boolean equals(Object o)
(e1.getKey()==null ?
e2.getKey()==null : e1.getKey().equals(e2.getKey())) &&
(e1.getValue()==null ?
e2.getValue()==null : e1.getValue().equals(e2.getValue()))
这确保equals方法在Map.Entry接口的不同实现中正常工作。
equals在类别
Object
o - 要与该地图条目相等的对象
Object.hashCode() , HashMap
int hashCode()
(e.getKey()==null ? 0 : e.getKey().hashCode()) ^
(e.getValue()==null ? 0 : e.getValue().hashCode())
这确保了e1.equals(e2)意味着e1.hashCode()==e2.hashCode()对于任何两个条目e1和e2,如要求的Object.hashCode总承包合同。
hashCode在类别
Object
Object.hashCode() ,
Object.equals(Object) ,
equals(Object)
static <K extends Comparable<? super K>,V> Comparator<Map.Entry<K,V>> comparingByKey()
Map.Entry 。
返回的比较器是可序列化的,当将条目与空键进行比较时,它将抛出NullPointerException 。
K - 那个地图键的Comparable类型
V - 地图值的类型
Map.Entry在自然顺序的关键。
Comparable
static <K,V extends Comparable<? super V>> Comparator<Map.Entry<K,V>> comparingByValue()
Map.Entry的自然顺序值。
返回的比较器是可序列化,并引发NullPointerException比较空值的条目时。
K - 地图键的类型
V - Comparable类型的地图值
Map.Entry的自然顺序。
Comparable
static <K,V> Comparator<Map.Entry<K,V>> comparingByKey(Comparator<? super K> cmp)
Map.Entry按键使用给定的Comparator 。
如果指定的比较器也可串行化,则返回的比较器是可序列化的。
K - 地图键的类型
V - 地图值的类型
cmp - 关键Comparator
Map.Entry的关键。
static <K,V> Comparator<Map.Entry<K,V>> comparingByValue(Comparator<? super V> cmp)
Comparator比较Map.Entry的值。
如果指定的比较器也可串行化,则返回的比较器是可序列化的。
K - 地图键的类型
V - 地图值的类型
cmp - 值Comparator
Map.Entry的值。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.