<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>map on Golang</title><link>https://golang.k5kc.com/tags/map/</link><description>Recent content in map on Golang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 16 Aug 2020 00:10:00 +0530</lastBuildDate><atom:link href="https://golang.k5kc.com/tags/map/index.xml" rel="self" type="application/rss+xml"/><item><title>"nil slice" vs "nil map"</title><link>https://golang.k5kc.com/2020/08/16/nil-slice-vs-nil-map/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/nil-slice-vs-nil-map/</guid><description>Slice and map are all reference types in Go, and their default values are nil:
package main import &amp;#34;fmt&amp;#34; func main() { var ( s []int m map[int]bool ) if s == nil { fmt.Println(&amp;#34;The value of s is nil&amp;#34;) } if m == nil { fmt.Println(&amp;#34;The value of m is nil&amp;#34;) } } The result is like this：
The value of s is nil The value of m is nil When a slice&amp;rsquo;s value is nil, you could also do operations on it, such as append:</description></item><item><title>Accessing Map</title><link>https://golang.k5kc.com/2020/08/16/accessing-map/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/accessing-map/</guid><description>Map is a reference type which points to a hash table, and you can use it to construct a &amp;ldquo;key-value&amp;rdquo; database which is very handy in practice programming. E.g., the following code will calculate the count of every element in a slice:
package main import ( &amp;#34;fmt&amp;#34; ) func main() { s := []int{1, 1, 2, 2, 3, 3, 3} m := make(map[int]int) for _, v := range s { m[v]++ } for key, value := range m { fmt.</description></item></channel></rss>