HashMap<K, V>
Hash-based key-value store with O(1) average lookup.
Type Constraints: K Constrains Hashable, V Constrains None
xxml
Language::CollectionsMethods
| Method | Parameters | Returns | Description |
|---|---|---|---|
| Constructor | — | HashMap<K,V>^ | Create empty map |
| put | key: K^, value: V^ | None | Insert or update |
| get | key: K^ | V^ | Get value by key |
| remove | key: K^ | Bool^ | Remove key-value pair |
| containsKey | key: K^ | Bool^ | Check if key exists |
| size | — | Integer^ | Number of pairs |
| isEmpty | — | Bool^ | Check if empty |
| clear | — | None | Remove all pairs |
| keys | — | List<K>^ | Get all keys |
| values | — | List<V>^ | Get all values |
| begin | — | HashMapIterator<K,V>^ | Get iterator |
Examples
HashMap Usage
xxml
Instantiate Collections::HashMap<String, Integer>^ As <ages> =
Collections::HashMap@String, Integer::Constructor();
Run ages.put(String::Constructor("Alice"), Integer::Constructor(30));
Run ages.put(String::Constructor("Bob"), Integer::Constructor(25));
Instantiate Integer^ As <aliceAge> = ages.get(String::Constructor("Alice")); // 30