March 2019
Intermediate to advanced
336 pages
9h 9m
English
Maps are used to keep track of keys that are types, such as integers, strings, float, double, pointers, interfaces, structs, and arrays. The values can be of different types. In the following example, the language of the map type with a key integer and a value string is created (maps.go):
var languages = map[int]string { 3: “English”, 4: “French”, 5: “Spanish”}
Maps can be created using the make method, specifying the key type and the value type. Products of a map type with a key integer and value string are shown in the following code snippet:
var products = make(map[int]string)products[1] = “chair”products[2] = “table”
A for loop is used for iterating through the map. The languages map is iterated as follows:
var i intvar value string ...
Read now
Unlock full access