tags:

views:

131

answers:

4

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

Is there any way to do it?

Actually that 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?

+9  A: 

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.

Bozho
A: 

Possibly browser returns String representation of some integer value? Actually int can't be null. May be you could check for null, if value is not null, then transform String representation to int.

Andriy Sholokh
+1  A: 

if your int variable is declared as a class level variable (instance variable) it would be defaulted to 0. But that does not indicate if the value sent from the client was 0 or a null. may be you could have a setter method which could be called to initialize/set the value sent by the client. then you can define your indicator value , may be a some negative value to indicate the null..

Siri
A: 

I think you are asking about code like this.

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