March 2020
Intermediate to advanced
406 pages
8h 39m
English
A map is a kind of container that is used to store key–value pairs. Go's built-in map type uses a hash table to store keys and their associated values.
In Go, instantiating a map is simple, as shown in the following code:
package mainimport "fmt"func main() { m := make(map[int]string) m[1] = "car" m[2] = "train" m[3] = "plane" fmt.Println("Full Map:\t ", m) fmt.Println("m[3] value:\t ", m[3]) fmt.Println("Length of map:\t ", len(m))}
Now let's have a look at the output:

In the preceding execution result, we can see that we can create a map, reference a value in a map by using its key, and find the number of elements in our map using the ...
Read now
Unlock full access