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

Get The Go Programming Language Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.