How to check if array is empty in Go

1 Answer

0 votes
package main

import "fmt"

func main() {
	var s []int
	
	fmt.Println(s, len(s))
	
	if s == nil {
		fmt.Println("empty")
	}
	if len(s) == 0 {
		fmt.Println("empty")
	}
}



/*
run:

[] 0
empty
empty

*/

 



answered Feb 27, 2020 by avibootz

Related questions

1 answer 102 views
2 answers 111 views
111 views asked Nov 7, 2024 by avibootz
2 answers 196 views
196 views asked Jun 25, 2021 by avibootz
1 answer 101 views
...