What is the method for initializing a map in Go language?

In Go language, you can initialize a map using the make function. The syntax of the make function is as follows:

make(map[keyType]valueType)

keyType refers to the type of keys in the map, while valueType refers to the type of values in the map. For example, to initialize a map with keys of type string and values of type int, you can use the following code:

m := make(map[string]int)

It is also possible to assign initial values to the map directly during initialization, for example:

m := map[string]int{
    "a": 1,
    "b": 2,
    "c": 3,
}

This creates a map with the keys “a”, “b”, and “c”, each corresponding to the values 1, 2, and 3, respectively.

bannerAds