Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle “int i != ""” or “int i != null” statements in Java?

Tags:

java

As we know int is a primitive data type and cannot be null. In my program i want to do a condition check like int i != "" but it says operator != cannot be applied to int,null.

Any solution?

EDIT:

I already know that it cannot hold these two things i was trying to present my requiremnet for checking the parameter i am getting from another server if it has recived some value or if its empty.

like image 208
Mohsin Sheikh Khalid Avatar asked Nov 10 '10 07:11

Mohsin Sheikh Khalid


2 Answers

You can use the Integer wrapper class for such comparisons. Otherwise the primitive int, if as a class field, defaults to 0 if not specified otherwise.

like image 158
dimitrisli Avatar answered Oct 12 '22 06:10

dimitrisli


compiler never speak un-truth .

int can't hold so there is no need to check for "" or null

like image 43
jmj Avatar answered Oct 12 '22 07:10

jmj