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. 一個(gè)由要害字映射到值的對(duì)象。一個(gè)map不能包含相同的要害字,每一個(gè)要害字至多映射到一個(gè)值。
This interface takes the place of the Dictionary class, which was a totally abstract class rather than an interface. 這個(gè)接口替換了Dictionary類——它是個(gè)完全的抽象類,而非接口。
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視圖訪問(wèn)map的內(nèi)容,包括key的set,值的collection,要害字—值映射對(duì)的set。 map的順序定義為map集合視圖迭代返回元素的順序。一些map的實(shí)現(xiàn),如TreeMap類,提供指定順序 的保證,而其他的如HashMap則沒(méi)有。
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. 注重:假如使用可變對(duì)象作為map的key時(shí),應(yīng)相當(dāng)小心。當(dāng)某對(duì)象是map中的key時(shí),以某種方式改變了對(duì)象值而影響相等性比較,那么map的行為不能確定。假如map以自身作為key,這樣的非凡情況是禁止的。然而map以自身作為值是答應(yīng)的,不過(guò)需要嚴(yán)重警告的是:這樣一個(gè)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的實(shí)現(xiàn)類都必須提供兩個(gè)標(biāo)準(zhǔn)構(gòu)造函數(shù):一個(gè)不含參數(shù)的空構(gòu)造函數(shù),創(chuàng)建一個(gè)空map,一個(gè)單Map類型參數(shù)的構(gòu)造函數(shù),使用和參數(shù)相同的映射關(guān)系創(chuàng)建一個(gè)新map。實(shí)際上,后者答應(yīng)用戶拷貝任何map來(lái)生成一個(gè)相等的map。雖然沒(méi)有辦法來(lái)強(qiáng)制執(zhí)行(因?yàn)榻涌诓缓瑯?gòu)造函數(shù))但是SDK中的所有通用map實(shí)現(xiàn)均是如此。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注