variable How to check whether a int is not null or empty?




java check if long is zero (3)

I really dont know if this is possible or not. But I am strucking in a place where I want to check an int value is null or not, to call different methods.

Is there any way to do it?

Actually, variable comes from a browser with a null value. I cannot change the int declaration to Integer. Because it has it own consequences.

Any suggestions?


int variables can't be null

If a null is to be converted to int, then it is the converter which decides whether to set 0, throw exception, or set another value (like Integer.MIN_VALUE). Try to plug your own converter.


I think you are asking about code like this.

int  count = (request.getParameter("counter") == null) ? 0 : Integer.parseInt(request.getParameter("counter"));

I think you can initialize the variables a value like -1, because if the int type variables is not initialized it can't be used. When you want to check if it is not the value you want you can check if it is -1.