From the course: Learning Go
Unlock this course with a free trial
Join today to access over 24,200 courses taught by industry experts.
Store unordered values in maps - Go Tutorial
From the course: Learning Go
Store unordered values in maps
- [Instructor] In the Go programming language, a map is an unordered collection of key value pairs. In other terms, it's a hash table that lets you store collections of data and then arbitrarily find items in the collection, based on their keys. A map's keys can be of any type that's comparable, that is the keys can be compared to each other for the purposes of sorting. But it's pretty common to use strings for keys and then any other type for associated values. I'm starting in a new version of my main.go file in my practice directory, and I'll create a new variable, and I'll initialize it with the make function. I'll parse in a type of map, then I'll set the key type wrapped in brackets to string and the associated value type also to string. Then I'll output the value of the map. And the output shows me that the map is empty, there's nothing between the brackets. Now I'll add items to the map. I'll say states, then…
Contents
-
-
-
-
-
How memory is allocated and managed3m 29s
-
(Locked)
Reference values with pointers4m 18s
-
(Locked)
Store ordered values in arrays3m 17s
-
(Locked)
Manage ordered values in slices4m 43s
-
(Locked)
Store unordered values in maps5m 54s
-
(Locked)
Group related values in structs4m 41s
-
(Locked)
Solution: Convert a slice of strings to a map2m 3s
-
-
-
-
-