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
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實現均是如此。
新聞熱點
疑難解答