Content deleted Content added
→Java: copy editing |
→JavaScript: copy editing |
||
Line 546:
Analogously, TreeMap, and other sorted data structures, require that an ordering be defined on the data type. Either the data type must already have defined its own ordering, by implementing the {{Javadoc:SE|java/lang|Comparable}} interface; or a custom {{Javadoc:SE|java/util|Comparator}} must be provided at the time the map is constructed. As with HashMap above, the relative ordering of keys in a TreeMap should not change once they have been inserted into the map.
===
[[JavaScript]] (and its standardized version
====Map and WeakMap====
Modern JavaScript handles associative arrays, using Map and WeakMap classes. A map does not contain any keys by default. It only contains what is explicitly put into it. The keys and values can be any
▲Modern JavaScript handles associative arrays using Map and WeakMap classes. A map does not contain any keys by default. It only contains what is explicitly put into it. The keys and values can be any value (including functions, objects, or any primitive).
▲=====''Creation''=====
A map can be initialized with all items during construction:
Line 575 ⟶ 573:
</syntaxhighlight>
=====
Accessing an element of the map can be done with the "get" method:▼
▲Accessing an element of the map can be done with the get method:
<syntaxhighlight lang=JavaScript>
|