MAP Function
Function Description
The MAP function is used to create a collection of key-value pairs, where each key corresponds to a value. This function allows multiple key-value pairs to be inserted at once, making it convenient for users to quickly construct a map-type data structure.
Syntax Format
Parameter Description
- k1, ..., kN : Represents the key parameters of the function, of type
K
. - v1, ..., vN : Represents the value parameters of the function, of type
V
.
Return Type
- Returns an object of type
map<K, V>
.
Usage Example
- Create a map containing two key-value pairs:
- Construct a map containing three key-value pairs, where one key has the same name but different values:
- Insert different types of key-value pairs (strings and integers) into the map:
- Create an empty map object:
Notes
- Ensure that the number of provided keys and values appear in pairs, otherwise the function execution will fail.
- If there are duplicate keys, the later key-value pairs will overwrite the earlier ones.
- The MAP function can accept keys and values of any type, but the keys must be of a comparable type to facilitate lookup in the map.