Hi,
Is there any other way to check null in string,without using == operator
Printable View
Hi,
Is there any other way to check null in string,without using == operator
Probably not. But what are you actually trying to do? Why do you think you should be avoiding the == operator in this case?
some times == can't work(like string objects) that's why i wanted to know any other way...
@veens: There is no way that == doesn't work.
== is a comparison operator that compares the referenced value of object.
What you will be trying to do is comparing the contents, not the referenced value.
So, for comparing the contents you can use equals(), while for comparing referenced value you must use ==
Hi,
Only when the left side value may be null then only == show exception so just try to avoid such on your code.
Core java
If I'm understanding you correctly, you're saying that this will cause an Exception:
...and that's simply not true. Using == to check null is the way to go.