MPS 2021.3 Help

Map

A map container backed by either a hash map or a linked hash map.

Map type

map<KeyType, ValueType >

Subtypes

Supertypes

Comparable types

sorted_map<KeyType, ValueType >

sequence< mapping<KeyType, ValueType > >

java.util.Map<KeyType, ValueType>

The map type is retrofitted to be a subtype of sequence.

Map creation

new hashmap

new linked_hashmap

Parameter type

Result type

(KeyType => ValueType)...

map<KeyType, ValueType >

Creates an empty map. Optionally, initial values may be specified right in the new map creation expression.

map<string, int> map = new hashmap<string, int> {"A" = 1, "B" = 2, "C" = 3};

Operations on map

get value by key

Operand type

Parameter type

Result type

map<KeyType, ValueType >

KeyType

ValueType

int value = map["key"];

keys

Operand type

Parameter type

Result type

map<KeyType, ValueType >

none

sequence<KeyType >

Results in a sequence containing all the keys in the map.

sequence<string> keys = map.keys;

containsKey

Operand type

Parameter type

Result type

map<KeyType, ValueType >

KeyType

boolean

Returns true if the map contains a mapping for the specified key, false otherwise.

map.containsKey ("key");

values

Operand type

Parameter type

Result type

map<KeyType, ValueType >

none

sequence<ValueType >

Results in a sequence containing all the values in the map.

sequence<string> values = map.values;

containsValue

Operand type

Parameter type

Result type

map<KeyType, ValueType >

ValueType

boolean

Returns true if the map contains a mapping with the specified value, false otherwise.

map.containsValue ("value");

mappings

Operand type

Parameter type

Result type

map<KeyType, ValueType >

none

set< mapping<KeyType, ValueType > >

Results in a set of mappings contained by this map. The mappings can be removed from the set, but not added.

set<mappings<K,V>> = map.mappings;

assign value to a key

Operand type

Parameter type

Result type

map<KeyType, ValueType >

KeyType

ValueType

map["key"] = value;

remove

Operand type

Parameter type

Result type

map<KeyType, ValueType >

KeyType

void

Removes the specified key and the associated value from the map.

map.remove ("key");

clear

Operand type

Parameter type

Result type

map<KeyType, ValueType >

none

void

Clears all key-value pairs from the map.

map.clear;

putAll

Operand type

Parameter type

Result type

map<KeyType, ValueType >

map<KeyType, ValueType >

void

Puts all mappings from the map specified as a parameter into this map, replacing existing mappings.

map.putAll (anotherMap);

Last modified: 14 September 2021