java.util.Map翻译
2008-01-05 18:32:55 来源:WEB开发网 Overview Package Class Use Tree DePRecated Index Help javaTM 2 Platform
Std. Ed. v1.4.2 PREV CLASS NEXT CLASSFRAMES NO FRAMES All Classes SUMMARY: NESTED FIELD CONSTR METHODDETAIL: FIELD CONSTR METHOD
java.util
Interface Map
- All Known Subinterfaces:
- SortedMap
- All Known Implementing Classes:
- AbstractMap, Attributes, HashMap, Hashtable, IdentityHashMap, RenderingHints, TreeMap, WeakHashMap
- public interface Map
An 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实现均是如此。
更多精彩
赞助商链接