0

We can write

if (usermailid != null) 

It is working but

if (usermailid =="Ram")  

is not working .

Brijesh Bhatt
  • 3,810
  • 3
  • 18
  • 34
Ruchi arora
  • 113
  • 1
  • 8
  • You can use expression language to compare strings (yes it works with strings!), just like this: ${usermailid == "Ram"} – Shota Apr 28 '15 at 11:34

2 Answers2

0
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

Brijesh Bhatt
  • 3,810
  • 3
  • 18
  • 34
0

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 NullPointerExceptions.

Also consider extracting the string being tested against as a constant, if it's used elsewhere.

Community
  • 1
  • 1
wonderb0lt
  • 2,035
  • 1
  • 23
  • 37