You are previewing The Go Programming Language Phrasebook.

The Go Programming Language Phrasebook

Cover of The Go Programming Language Phrasebook by David Chisnall Published by Addison-Wesley Professional
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 ...

The best content for your career. Discover unlimited learning on demand for around $1/day.