xxxxxxxxxx
Search Results
Featured snippet from the web
In Go language, a map is a powerful, ingenious, and a versatile data structure. Golang Maps is a collection of unordered pairs of key-value. It is widely used because it provides fast lookups and values that can retrieve, update or delete with the help of keys. It is a reference to a hash table.
xxxxxxxxxx
//map in go is a built in type implementaiton of has table
//create an empty map
myMap := make(map[string]string)
//insert key-value pair in map
myMap["key"] = "value"
//read from map
value, ok := myMap["key"]
//delete from map
delete(myMap, "key")
xxxxxxxxxx
package main
import "fmt"
func main() {
object := map[string]string{
"name": "john doe",
}
arrayObject := []map[string]string{
map[string]string{ "name": "john doe"},
map[string]string{"name": "jane doe"},
}
usingMake := make(map[string] string)
usingMake["name"] = "max cavalera"
fmt.Printf("this is object %v \n", object)
fmt.Printf("this is array object %v \n", arrayObject)
fmt.Printf("using make method %v \n", usingMake)
}
xxxxxxxxxx
// Program to create a map and print its keys and values
package main
import ("fmt")
func main() {
// creating a map
subjectMarks := map[string]float32{"Golang": 85, "Java": 80, "Python": 81}
fmt.Println(subjectMarks)
}