| JavaTM 2 Platform Std. Ed. v1.4.2 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES <script type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> </script> All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.util
Interface Map.Entry
-
Enclosing interface:
- Map
-
public static interface 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 iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator. 映射项(键-值对)。Map.entrySet方法返回映射的集合视图,它的元素为本类。 或取映射项引用的唯一方法是从集合视图的迭代器中获取。如果原映射在迭代器返回项(除迭代器自身的remove操作 或者通过迭代器返回的映射项的setValue操作而外)时 已被修改,则映射项的行为不能确定。
-
Since:
- 1.2 See Also:
-
Map.entrySet()
Method Summary | |
boolean | equals(Object o) Compares the specified object with this entry for equality. 将指定对象同该项比较相等性。 |
Object | getKey() Returns the key corresponding to this entry. 返回与该项对应的键。 |
Object | getValue() Returns the value corresponding to this entry. 返回与该项对应的值。 |
int | hashCode() Returns the hash code value for this map entry. 返回该映射项的hash码值。 |
Object | setValue(Object value) Replaces the value corresponding to this entry with the specified value (optional operation). 使用指定的值替换该项对应的值(可选操作)。 |
Method Detail |
getKey
public Object getKey()
- Returns the key corresponding to this entry. 返回与该项对应的键。
-
-
Returns:
- the key corresponding to this entry. 与该项对应的键。
getValue
public Object getValue()
- 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. 返回与该项对应的值。如果映射关系已经从原映射中删除(通过迭代器的remove操作), 则该调用的结果不能确定。
-
-
Returns:
- the value corresponding to this entry. 与该项对应的值。
setValue
public Object setValue(Object value)
- 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). 使用指定的值替换该项对应的值(可选操作)(写入映射)。如果映射关系已经从映射中删除(通过迭代器的remove操作), 则该调用的行为不能确定。
-
-
Parameters:
-
value
- new value to be stored in this entry. 要存储在该项中的新值。
Returns:
- old value corresponding to the entry. 对应该项的旧值。 Throws:
-
UnsupportedOperationException
- if the put operation is not supported by the backing map. 如果原映射不支持put方法时抛出。 -
ClassCastException
- if the class of the specified value prevents it from being stored in the backing map. 如果指定值的类阻止存储在原映射中抛出。 -
IllegalArgumentException
- if some aspect of this value prevents it from being stored in the backing map. 如果该值的某方面阻止存储在原映射中抛出。 -
NullPointerException
- the backing map does not permit null values, and the specified value is null. 如果指定值为null,而原映射不允许null时抛出。
-
equals
public boolean equals(Object o)
-
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 将指定对象同该项比较相等性。如果给定的对象也是一个映射项,两个项表示相同的映射时返回true。 如果以下
(e1.getKey()==null ? e2.getKey()==null : e1.getKey().equals(e2.getKey())) && (e1.getValue()==null ? e2.getValue()==null : e1.getValue().equals(e2.getValue()))
成立,两个项e1和e2表示相同的映射 This ensures that the equals method works properly across different implementations of the Map.Entry interface. 这确保Map.Entry接口即便不同实现,该方法也表示equals方法工作一致。 -
-
Parameters:
-
o
- object to be compared for equality with this map entry. 用来和映射项比较相等性的对象
Returns:
- true if the specified object is equal to this map entry. 如果指定对象和该映射项相等时返回tru。 See Also:
-
Object.hashCode()
,Hashtable
-
hashCode
public int hashCode()
-
Returns the hash code value for this map entry. The hash code of a map entry e is defined to be: 返回该映射项的hash码值。一个映射项e的hash码被定义为:
(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. 这确保对于任意两个项e1和e2,按照Object.hashCode的通常约定,e1.equals(e2)意味着e1.hashCode()==e2.hashCode() -
-
Returns:
- the hash code value for this map entry. 该映射项的hash码值。 See Also:
-
Object.hashCode()
,Object.equals(Object)
,equals(Object)
| JavaTM 2 Platform Std. Ed. v1.4.2 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES <script type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> </script> All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation . That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.