Maps: Key-Value Stores
Creating, reading, writing and deleting map entries
What Is a Map?
A map in Go is an unordered collection of key-value pairs. Keys must be a comparable type (strings, ints, etc.). Maps are reference types backed by a hash table.
Creating Maps
Use a literal or make:
package main
import "fmt"
func main() {
ages := map[string]int{"Alice": 30, "Bob": 25}
cache := make(map[string]string)
fmt.Println(ages, cache)
}All lessons in this course
- Arrays: Fixed-Length Collections
- Slices: Dynamic Lists
- Maps: Key-Value Stores
- Iterating Collections with range