O'Reilly logo

The Go Programming Language Phrasebook by David Chisnall

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7. Working with Collections

Go, in common with most other languages, provides arrays as a fundamental low-level collection type. It adds slices on top of arrays to provide a safe way of accessing arbitrary memory ranges.

In the standard library, Go also provides a small range of collection types, but there’s also one more that is part of the language: maps. Other languages call these dictionaries, associative arrays, or (not quite accurately) hash tables. They define a unique set of keys, each of which has one value associated with it.

Creating a Map

 1  package main 2  import "fmt" 3 4  type Any interface {} 5 6  func main() { 7    a := make(map[int] string) 8    b := make(map[Any] int) 9    a[12] = "A string in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required