Thus, str.equals(null) will always return false because there is no such object reference as null in reality.
So only str==null can help you.
However, a more strong way to check if a str object contains any char or not is
if str==null str.equals("")
{
...
}
Other way is just perform the operation on the str in a try-catch block catching the NullPointerException like
try {
str.substring(0, 2);
}catch(NullPointerException)
{
e.printStackTrace();
}
No comments:
Post a Comment