Cover page by David Chisnall

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

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 ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required