Map is a key-value data structure, also known as a field or associative array. Collections similar to other programming languages
1. Basic syntax
var variable name map[keytype]valuetype
// Make before using map// The map key cannot be repeated. If it is repeated, the last key-value shall prevail// The key-value of map is unorderedvar a map[string]string a = make(map[string]string, 10) a["n1"] = "a" a["n2"] = "b" a["n3"] = "c"
2. How to use
Declare first, then make
var a map[string]string a = make(map[string]string, 10)
Declare directly make
a := make(map[string]string, 10)
Declare direct assignment
var a map[string]string = map[string]string{ "n1" : "Song Jiang" "n2" : "Lu Junyi" }
3. Add, delete, modify and check
a := make(map[string]string, 10) // If there is no such key, it will be increased, and if there is any, it will be modified.a["n1"] = "aa" delete(a, "n1") val, res := a["n1"] //Find Res is true, otherwise it is false if res { ("Finished") } else { ("Not arrived") }
This is the article about the methods and steps of golang mapping Map. For more related golang mapping Map content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!