Home > Backend Development > Golang > How to determine whether int is empty in Golang

How to determine whether int is empty in Golang

Release: 2020-01-13 09:41:51
Original
11315 people have browsed it

How to determine whether int is empty in Golang

Golang is a programming language developed by Google that is statically strongly typed, compiled, concurrently typed, and has garbage collection capabilities. Int is a reserved keyword in golang. Let's take a look at the method of determining whether int is empty in golang.

Method 1:

First convert the int type data into the String type, and then determine whether the String type data is empty.

Sample code:

int point; 
String val=point +""; 
if("".equals(val)){ 
// do something...
}
Copy after login

PS: int point is not an object, and the default is 0 when the int type is empty.

Method 2:

If point is of type int, the result obtained cannot be null.

If no field is inserted when inserting a piece of data, and the default value in the database is null, you can use

Integer point= GiftInfo.getPoints();
Copy after login

and then determine whether point is equal to null.

Sample code:

Integer point= GiftInfo.getPoints();
if(point == null){ 
// do something...
}
Copy after login

For more golang knowledge, please pay attention to the golang tutorial column on the PHP Chinese website.

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

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template