English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Erlang Maps (Map)

Mapping is a data structure with a variable number of keys-Composite data type associated with values. Each key-value association in the mapping is called an association pair. The key and value parts of the pair are called elements. The number of association pairs is called the size of the mapping.

The following program demonstrates an example of how to use the Map data type.

Here we define a Map M1It has2a map.map_size is a built-in function defined in Erlang, which can be used to determine the size of a map.

Online Example

-module(helloworld). 
-export([start/ 
start() -> 
   M1 =  #{name=>john,age=>25}, 
   io:fwrite("~w",[map_size(M1)]).

The output of the above program is as follows.

2

Some other methods applicable to maps are as follows.

Serial NumberMethods and Descriptions
1

from_list

This method is used to generate a map from a list.

2

find

This method is used to find if a specific key exists in the map.

3

get

This method is used to get the value of a specific key in the map.

4

is_key

This method is used to determine if a specific key is defined as a key in the map.

5

keys

This method is used to return all keys from the map.

6

merge

This method is used to merge2A map.

7

put

This method is used to add a key-value pair to the map.

8

values

This method is used to return all values from the map.

9

remove

This method is used to remove the key-value from the map.