Skip to content

How to Create an Empty Slice in Golang

If you would like to create an empty slice in Go, then you can do the following:

Option 1 – Initialize an Empty Slice in Go

package main import "fmt" func main() { b := []string{} fmt.Println(b == nil) }
Code language: Go (go)

Option 2 – Using make()

package main import "fmt" func main() { c := make([]string, ) fmt.Println(c == nil) }
Code language: Go (go)

See also  Find the Minimum Absolute Difference in BST using Java
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x