The Dictionary class lets you create a dynamic collection of properties, which uses strict equality for key comparison. When an object is used as a key, the object's identity is used to look up the object, and not the value returned from calling toString() on it.

The following statements show the relationship between a Dictionary object and a key object:

var dict = new Dictionary<Any, Any>();
var obj:Any = {};
var key:Any = {
	toString: function() {
		return "key";
	}
};

dict[key] = "Letters";
Reflect.setField(obj, "key", "Letters");

trace(dict[key] == "Letters"); // true
trace(Reflect.field(obj, "key") == "Letters"); // true
trace(Reflect.field(obj, Std.string(key)) == "Letters"); // true because key == "key" is true b/c key.toString == "key"
trace(dict["key"] == "Letters"); // false because "key" === key is false
dict.remove(key); // removes the key
trace(dict[key] == null); // true

Static methods

staticinlineeach(this:IMap<K, V>):Iterator<V>

Returns an Iterator over each of the values of this Dictionary.

The order of values is undefined.

staticinlineexists(this:IMap<K, V>, key:K):Bool

Returns true if key has a mapping, false otherwise.

If key is null, the result is unspecified.

@:arrayAccessstaticinlineget(this:IMap<K, V>, key:K):V

Returns the current mapping of key.

If no such mapping exists, null is returned.

Note that a check like dict.get(key) == null can hold for two reasons:

  1. The Dictionary has no mapping for key
  2. The Dictionary has a mapping with a value of null

If it is important to distinguish these cases, exists() should be used.

If key is null, the result is unspecified.

staticinlineiterator(this:IMap<K, V>):Iterator<K>

Returns an Iterator over the keys of this Dictionary.

The order of values is undefined.

staticinlinekeyValueIterator(this:IMap<K, V>):KeyValueIterator<K, V>

Returns an Iterator over the keys and values of this Dictionary.

The order of values is undefined.

staticinlineremove(this:IMap<K, V>, key:K):Bool

Removes the mapping of key and returns true if such a mapping existed, false otherwise.

If key is null, the result is unspecified.

@:arrayAccessstaticinlineset(this:IMap<K, V>, key:K, value:V):V

Maps key to value.

If key already has a mapping, the previous value disappears.

If key is null, the result is unspecified.