Create Empty Map
To create an empty Map in Go language, we can either use make() function with map type specified or use map initializer with no key:value pairs given.
Create an empty Map: string->string using make() function with the following syntax.
</>
Copy
make(map[string]string)
Create an empty Map: string->string using Map initializer with the following syntax.
</>
Copy
make(map[string]string)
Examples
Empty Map using make()
In the following example, we create an empty Map with key of type string and value of type string, using make() function.
Example.go
</>
Copy
package main
import "fmt"
func main() {
x := make(map[string]string)
fmt.Println(x)
}
Output
map[]
Empty Map using Map Initializer
In the following example, we create an empty Map with key of type string and value of type string, using Map initializer. Pass no key:value pairs in the curly braces.
Example.go
</>
Copy
package main
import "fmt"
func main() {
x := map[string]string{}
fmt.Println(x)
}
Output
map[]
Conclusion
In this Go Tutorial, we learned how to create an empty Map in Go language, with the syntax and example programs.