分享
 
 
 

java.util.Map翻译

王朝java/jsp·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

[/url] [url=file:///F:/资料/文字资料/j2sdk-1_4_2-doc/docs/api/overview-summary.html]Overview

Package

Class

Use

Tree

Deprecated

Index

Help

JavaTM 2 Platform

Std. Ed. v1.4.2

PREV CLASS NEXT CLASS

FRAMES NO FRAMES All Classes

SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

java.util

Interface MapAll Known Subinterfaces: SortedMap All Known Implementing Classes: AbstractMap, Attributes, HashMap, Hashtable, IdentityHashMap, RenderingHints, TreeMap, WeakHashMap public interface MapAn object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. 一个由关键字映射到值的对象。一个map不能包含相同的关键字,每一个关键字至多映射到一个值。

This interface takes the place of the Dictionary class, which was a totally abstract class rather than an interface. 这个接口替换了Dictionary类——它是个完全的抽象类,而非接口。

The Map interface provides three collection views, which allow a map's contents to be viewed as a set of keys, collection of values, or set of key-value mappings. The order of a map is defined as the order in which the iterators on the map's collection views return their elements. Some map implementations, like the TreeMap class, make specific guarantees as to their order; others, like the HashMap class, do not. Map接口提供了三种collection视图访问map的内容,包括key的set,值的collection,关键字—值映射对的set。 map的顺序定义为map集合视图迭代返回元素的顺序。一些map的实现,如TreeMap类,提供指定顺序 的保证,而其他的如HashMap则没有。

Note: great care must be exercised if mutable objects are used as map keys. The behavior of a map is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is a key in the map. A special case of this prohibition is that it is not permissible for a map to contain itself as a key. While it is permissible for a map to contain itself as a value, extreme caution is advised: the equals and hashCode methods are no longer well defined on a such a map. 注意:如果使用可变对象作为map的key时,应相当小心。当某对象是map中的key时,以某种方式改变了对象值而影响相等性比较,那么map的行为不能确定。如果map以自身作为key,这样的特殊情况是禁止的。然而map以自身作为值是允许的,不过需要严重警告的是:这样一个map,所定义的equals和hashCode方法将不再有效。

All general-purpose map implementation classes should provide two "standard" constructors: a void (no arguments) constructor which creates an empty map, and a constructor with a single argument of type Map, which creates a new map with the same key-value mappings as its argument. In effect, the latter constructor allows the user to copy any map, producing an equivalent map of the desired class. There is no way to enforce this recommendation (as interfaces cannot contain constructors) but all of the general-purpose map implementations in the SDK comply. 所有通用map的实现类都必须提供两个标准构造函数:一个不含参数的空构造函数,创建一个空map,一个单Map类型参数的构造函数,使用和参数相同的映射关系创建一个新map。实际上,后者允许用户拷贝任何map来生成一个相等的map。虽然没有办法来强制执行(因为接口不含构造函数)但是SDK中的所有通用map实现均是如此。

The "destructive" methods contained in this interface, that is, the methods that modify the map on which they operate, are specified to throw UnsupportedOperationException if this map does not support the operation. If this is the case, these methods may, but are not required to, throw an UnsupportedOperationException if the invocation would have no effect on the map. For example, invoking the putAll(Map) method on an unmodifiable map may, but is not required to, throw the exception if the map whose mappings are to be "superimposed" is empty. 该接口包含了一些破坏性的方法,操作的时候修改map,如果map不支持这些操作,规定应该抛出UnsupportedOperationException。如果调用对map没影响,在这种情况下,这些方法可以抛出UnsupportedOperationException,但不必须。例如对于一个不可更新的map (map的映射关系为空)调用putAll(Map)方法,可以抛出该异常,而不是必须。

Some map implementations have restrictions on the keys and values they may contain. For example, some implementations prohibit null keys and values, and some have restrictions on the types of their keys. Attempting to insert an ineligible key or value throws an unchecked exception, typically NullPointerException or ClassCastException. Attempting to query the presence of an ineligible key or value may throw an exception, or it may simply return false; some implementations will exhibit the former behavior and some will exhibit the latter. More generally, attempting an operation on an ineligible key or value whose completion would not result in the insertion of an ineligible element into the map may throw an exception or it may succeed, at the option of the implementation. Such exceptions are marked as "optional" in the specification for this interface. 某些map实现对其包含的key和值有限制。比如,某些实现禁止null key和值,某些对key的类型有限制。试图插入一个不合适的key或值将抛出未检查异常,通常为NullPointerException或ClassCastException。试图查询一个不合适的key或值可以抛出异常,也可以简单返回false。某些实现表现为前者,某些表现为后者。更一般地讲,试图操作一个不适当的key或值,实现不会造成不适当元素插入map而抛出异常或者成功,这取决于实现的选择。那样的异常在该接口规范中标记为“optional”。

This interface is a member of the Java Collections Framework. 该接口是Java集合框架成员之一。

Since: 1.2 See Also: HashMap, TreeMap, Hashtable, SortedMap, Collection, SetNested Class Summary

static interface

Map.Entry

A map entry (key-value pair). map项(键-值对)。

Method Summary

void

clear()

Removes all mappings from this map (optional operation). 删除map中的所有映射关系(可选操作)。

boolean

containsKey(Object key)

Returns true if this map contains a mapping for the specified key. 如果map中包含指定key的映射关系,返回true。

boolean

containsValue(Object value)

Returns true if this map maps one or more keys to the specified value. 如果map中能够应设一个或多个key至指定的值,返回true。

Set

entrySet()

Returns a set view of the mappings contained in this map. 返回map中包含的映射关系的set视图。

boolean

equals(Object o)

Compares the specified object with this map for equality. 将指定对象与此map就相等性进行比较。

Object

get(Object key)

Returns the value to which this map maps the specified key. 返回map中映射指定key的值。

int

hashCode()

Returns the hash code value for this map. 返回map的hash码值。

boolean

isEmpty()

Returns true if this map contains no key-value mappings. 如果map中不含键值对映射关系,返回true。

Set

keySet()

Returns a set view of the keys contained in this map. 返回map中包含的key的set视图。

Object

put(Object key, Object value)

Associates the specified value with the specified key in this map (optional operation). 将指定key和指定值映射至map(可选操作)。

void

putAll(Map t)

Copies all of the mappings from the specified map to this map (optional operation). 从指定map向此map复制所有映射关系(可选操作)。

Object

remove(Object key)

Removes the mapping for this key from this map if it is present (optional operation). 如果该key存在,从map中删除对应的映射关系(可选操作)。

int

size()

Returns the number of key-value mappings in this map. 返回map中键值对映射关系的数目。

Collection

values()

Returns a collection view of the values contained in this map. 返回map中包含的值的collection视图。

Method Detail

sizepublic int size()

Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE. 返回map中键值对映射关系的数目。如果map中包含的元素数目大于Integer.MAX_VALUE,则返回Integer.MAX_VALUE。

Returns: the number of key-value mappings in this map. map中键值对映射关系的数目。isEmptypublic boolean isEmpty()

Returns true if this map contains no key-value mappings. 如果map中不含键值对映射关系,返回true。

Returns: true if this map contains no key-value mappings. 如果map中不含键值对映射关系,返回true。containsKeypublic boolean containsKey(Object key)

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains at a mapping for a key k such that (key==null ? k==null : key.equals(k)). (There can be at most one such mapping.) 如果map中包含指定key的映射关系,返回true。正式表述为,只有当map包含key k的映射,使得 (key==null ? k==null : key.equals(k))时,返回true。(至多只有一个那样的映射。)

Parameters: key - key whose presence in this map is to be tested. 测试key是否存在的map。 Returns: true if this map contains a mapping for the specified key. 如果map中包含指定key的映射关系,返回true。 Throws: ClassCastException - if the key is of an inappropriate type for this map (optional). 如果key的类型对于map而言不适当抛出(可选)。 NullPointerException - if the key is null and this map does not not permit null keys (optional). 如果key为null,而map不允许null key时抛出(可选)。containsValuepublic boolean containsValue(Object value)

Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that (value==null ? v==null : value.equals(v)). This operation will probably require time linear in the map size for most implementations of the Map interface. 如果map中能够应设一个或多个key至指定的值,返回true。正式表述为,只有当map包含至少一个到值v的映射,使得 (key==null ? k==null : key.equals(k))时,返回true。该操作可能需要的时间对于Map接口的大多数实现而言, 和map大小成线性关系。

Parameters: value - value whose presence in this map is to be tested. 测试是否在map存在的值。 Returns: true if this map maps one or more keys to the specified value. 如果map中能够应设一个或多个key至指定的值,返回true。 Throws: ClassCastException - if the value is of an inappropriate type for this map (optional). 如果值的类型对于map而言不适当抛出(可选)。 NullPointerException - if the value is null and this map does not not permit null values (optional). 如果值为null,而map不允许null值时抛出(可选)。getpublic Object get(Object key)

Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases. 返回map中映射指定key的值。如果map不含该key的映射,返回null。返回值null并不一定表示map包含该值的映射,也有可能是map中映射到key的值为null。可以使用containsKey操作来区分这两种情况。 More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.) 正式表述为,如果map不含从key k到值v的映射,使得(key==null ? k==null : key.equals(k)), 那么方法返回v;否则返回null。(至多有一个这样的映射。)

Parameters: key - key whose associated value is to be returned. 要返回的与值关联的key。 Returns: the value to which this map maps the specified key, or null if the map contains no mapping for this key. map映射指定key的值,如果map不含该key的映射,返回null。 Throws: ClassCastException - if the key is of an inappropriate type for this map (optional). 如果key的类型对于map而言不适当抛出(可选)。 NullPointerException - key is null and this map does not not permit null keys (optional). 如果key为null,而map不允许null key时抛出(可选)。 See Also: containsKey(Object)putpublic Object put(Object key,

Object value)

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for this key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)) 将指定key和指定值映射至map(可选操作)。如果map已包含该key的映射,用指定值替换旧值。 (只有当m.containsKey(k)返回true是,才可以说map m包含了key k的映射。)

Parameters: key - key with which the specified value is to be associated. 要关联指定值的key。 value - value to be associated with the specified key. 要关联指定key的值。 Returns: previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values. 与指定key关联的原值,如果没有此key的映射,返回null。如果实现支持null值的话, 返回null可能也表示map中指定key的原关联值为null。 Throws: UnsupportedOperationException - if the put operation is not supported by this map. 如果当前map不支持put操作时抛出。 ClassCastException - if the class of the specified key or value prevents it from being stored in this map. 如果指定key或值的类型不允许其存入map时抛出。 IllegalArgumentException - if some aspect of this key or value prevents it from being stored in this map. 如果指定key或值的某些方面不允许其存入map时抛出。 NullPointerException - this map does not permit null keys or values, and the specified key or value is null. 指定key或值为null,而map不允许null key或值时抛出。removepublic Object remove(Object key)

Removes the mapping for this key from this map if it is present (optional operation). More formally, if this map contains a mapping from key k to value v such that (key==null ? k==null : key.equals(k)), that mapping is removed. (The map can contain at most one such mapping.) 如果该key存在,从map中删除对应的映射关系(可选操作)。正式表述为,如果map含从key k到值 v的映射,使得(key==null ? k==null : key.equals(k)),那么删除该映射。 Returns the value to which the map previously associated the key, or null if the map contained no mapping for this key. (A null return can also indicate that the map previously associated null with the specified key if the implementation supports null values.) The map will not contain a mapping for the specified key once the call returns. 返回的值为map中关联key的原值,如果map不含该key的映射,返回null。 (如果实现支持null值的话,返回null也可能表示map中关联指定key的原值为null。) 一旦调用返回,map将不再包含指定key的映射。

Parameters: key - key whose mapping is to be removed from the map. 要从map删除映射的key。 Returns: previous value associated with specified key, or null if there was no mapping for key. 与指定key关联的原值,如果没有key的映射,返回null。 Throws: ClassCastException - if the key is of an inappropriate type for this map (optional). 如果key的类型对于map而言不适当抛出(可选)。 NullPointerException - if the key is null and this map does not not permit null keys (optional). 如果key为null,而map不允许null key时抛出(可选)。 UnsupportedOperationException - if the remove method is not supported by this map. 如果当前map不支持remove操作时抛出。putAllpublic void putAll(Map t)

Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is unspecified if the specified map is modified while the operation is in progress. 从指定map向此map复制所有映射关系(可选操作)。 该调用的效果相当于对指定map中的每个从key k到值v的映射调用put(k, v)。 如果操作进行中指定map被修改,操作行为不能确定。

Parameters: t - Mappings to be stored in this map. 要存储在当前map中的映射。 Throws: UnsupportedOperationException - if the putAll method is not supported by this map. 如果当前map不支持putAll操作时抛出。 ClassCastException - if the class of a key or value in the specified map prevents it from being stored in this map. 如果指定map中的某个key或值的类型不允许其存入map时抛出。 IllegalArgumentException - some aspect of a key or value in the specified map prevents it from being stored in this map. 如果指定map中的某个key或值的某些方面不允许其存入map时抛出。 NullPointerException - the specified map is null, or if this map does not permit null keys or values, and the specified map contains null keys or values. 指定map为null,或者当前map不允许null key或值,而指定map包含了null key或值时抛出。clearpublic void clear()

Removes all mappings from this map (optional operation). 删除map中的所有映射关系(可选操作)。

Throws: UnsupportedOperationException - clear is not supported by this map. 如果当前map不支持clear操作时抛出。keySetpublic Set keySet()

Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support the add or addAll operations. 返回map中包含的key的set视图。set由map返回,因此对map的修改会影响到set。 如果正当遍历set时map被修改,遍历的结果不能确定。set支持元素删除,通过 Iterator.remove、Set.remove、removeAll、retainAll和clear操作从map中删除 对应的映射关系。它不支持add或者addAll操作。

Returns: a set view of the keys contained in this map. map中包含的key的set视图。valuespublic Collection values()

Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations. 返回map中包含的值的collection视图。集合由map返回,因此对map的修改会影响到集合。 如果正当遍历集合时map被修改,遍历的结果不能确定。集合支持元素删除,通过 Iterator.remove、Collection.remove、removeAll、retainAll和clear操作从map中删除 对应的映射关系。它不支持add或者addAll操作。

Returns: a collection view of the values contained in this map. map中包含的值的collection视图。entrySetpublic Set entrySet()

Returns a set view of the mappings contained in this map. Each element in the returned set is a Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations. 返回map中包含的映射关系的set视图。返回set中每一个元素是一个Map.Entry,set由map返回,因此对map的修改会影响到set。 如果正当遍历set时map被修改,遍历的结果不能确定。set支持元素删除,通过 Iterator.remove、Set.remove、removeAll、retainAll和clear操作从map中删除 对应的映射关系。它不支持add或者addAll操作。

Returns: a set view of the mappings contained in this map. map中包含的映射关系的set视图。equalspublic boolean equals(Object o)

Compares the specified object with this map for equality. Returns true if the given object is also a map and the two Maps represent the same mappings. More formally, two maps t1 and t2 represent the same mappings if t1.entrySet().equals(t2.entrySet()). This ensures that the equals method works properly across different implementations of the Map interface. 将指定对象与此map就相等性进行比较。如果给定的对象也是一个map,两个map表示相同的映射关系,返回true。 正式表述为,如果t1.entrySet().equals(t2.entrySet()),两个map t1和t2表示相同的映射关系。 这将确保对于Map接口的不同实现,

Overrides: equals in class ObjectParameters: o - object to be compared for equality with this map. 同当前map比较相等性的对象。 Returns: true if the specified object is equal to this map. 如果指定对象等于当前map,返回true。 See Also: Object.hashCode(), HashtablehashCodepublic int hashCode()

Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hashCodes of each entry in the map's entrySet view. This ensures that t1.equals(t2) implies that t1.hashCode()==t2.hashCode() for any two maps t1 and t2, as required by the general contract of Object.hashCode. 返回map的hash码值。map的hash码定义为map entrySet视图中每一个项的hash码的和。 这确保对于任意两个map t1和t2,按照Object.hashCode的通常约定,t1.equals(t2)意味着t1.hashCode()==t2.hashCode()。

Overrides: hashCode in class ObjectReturns: the hash code value for this map. map的hash码值。 See Also: Map.Entry.hashCode(), Object.hashCode(), Object.equals(Object), equals(Object)[/url][url=file:///F:/资料/文字资料/j2sdk-1_4_2-doc/docs/api/overview-summary.html]Overview

Package

Class

Use

Tree

Deprecated

Index

Help

JavaTM 2 Platform

Std. Ed. v1.4.2

PREV CLASS NEXT CLASS

FRAMES NO FRAMES 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.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有