String comparison – Android [duplicate]

Try this

if(gender.equals("Male"))
 salutation ="Mr.";
if(gender.equals("Female"))
 salutation ="Ms.";

Also remove ;(semi-colon ) in your if statement

if(gender.equals(g1));

In Java, one of the most common mistakes newcomers meet is using == to compare Strings. You have to remember, == compares the object references, not the content.

Leave a Comment