in my project ,Somewhere I have to use if n else condition to check the null variables
String stringValue = null;
String valueOf = String.valueOf(stringValue);
but when i check the condition like
if (valueOf == null) {
System.out.println("in if");
} else {
System.out.println("in else");
}
then output is “in else” ,why this is happening?
Here’s the source code of
String.valueOf: –As you can see, for a
nullvalue it returns"null"string.So,
gives
"null"string to thevalueOf.Similarly, if you do: –
You will get: –
EDIT
Another Example:
But in this case.