Home > Backend Development > Golang > How to determine whether an array is empty in golang

How to determine whether an array is empty in golang

Release: 2019-12-25 09:41:37
Original
5296 people have browsed it

How to determine whether an array is empty in golang

Array is one of the most commonly used data structures in Go language programming. As the name suggests, an array refers to a series of collections of data of the same type. Each data contained in the array is called an array element, and the number of elements an array contains is called the length of the array. One thing that needs to be emphasized is that the length of arrays in Go language is fixed and cannot be expanded.

java determines whether an array is empty:

package main
 
import "fmt"
 
func main() {
	var arr []string
	
	if arr == nil {
		fmt.Println("this is null")
	}
 
	if len(arr) > 0 {
		fmt.Println("len arr > 0")
	}else{
		fmt.Println("len this is null")
	}
	
	if arr[0] != "" {
		fmt.Println("arr 0 != null")	
	}else{
		fmt.Println("[0] this is null")
	}
 
}
Copy after login

nil in Go is equivalent to NULL, null and None in other languages. When used, it means that a certain variable is empty.

For more golang knowledge, please pay attention to the golang tutorial column.

The above is the detailed content of How to determine whether an array is empty in golang. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
How to choose golang web mvc framework
From 1970-01-01 08:00:00
0
0
0
Is it necessary to use nginx when using golang?
From 1970-01-01 08:00:00
0
0
0
golang - vim plug-in to write go
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template