title: String comparison - Android
body: <p>I'm unable to compare two strings using the following code:</p>
  
  <p>I have a string named "gender" which will have "Male" or "Female" as its value.</p>
  
  <pre><code>if(gender == "Male")
     salutation ="Mr.";
  if(gender == "Female")
     salutation ="Ms.";
  </code></pre>
  
  <p>This didn't work, so I tried the following:</p>
  
  <pre><code>String g1="Male";
  String g2="Female";
  if(gender.equals(g1))
     salutation ="Mr.";
  if(gender.equals(g2))
     salutation ="Ms.";
  </code></pre>
  
  <p>Again, it didn't work.
  Can someone please tell me how to compare string values using the if statement.</p>