This might sound like a real dumb question but please bear with me 🙂
so I have a if condition in my code like if ((msgBO.getEmpId().equals("") == false )) { My question is, if I make the above statement as
// do something
}msgBO.getEmpId().equals(null) == false
would it make any difference or this way I am trying to compare two different things?
This might sound like a real dumb question but please bear with me :)
Share
Yes, there is a big difference between
""(the empty String) andnull(no String at all).Any Object reference can point to
null. That represents ‘no data’ or ‘nothing.’ The empty string""represents a String with no length.An example of this is the following:
The first call to
lengthwill throw aNullPointerException. And the second will return0.