We can write
if (usermailid != null)
It is working but
if (usermailid =="Ram")
is not working .
We can write
if (usermailid != null)
It is working but
if (usermailid =="Ram")
is not working .
if (usermailid.equals("Ram"))
this will check the equality.
==
will compare the reference of both objects which is not same.
For you Reference to JAVA string functions, refer this
As Brijesh pointed out, ==
checks equality and you should use equals
as outlined extensively in this answer.
More efficiently, you could combine null check and check against value in one expression, like so
if ("Ram".equals(usermailid)) { /* ... */ }
The equals
check fails if the value is null too, so you don't have to check both in seperate conditions and don't run the risk of NullPointerException
s.
Also consider extracting the string being tested against as a constant, if it's used elsewhere.