-2

Hi please explain how to use equals () in Android Studio when using strings to replace String1==String2

  • 1
    Possible duplicate of [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Michael Dodd Mar 08 '17 at 16:12

1 Answers1

0

To compare two strings, use String.equals

string1.equals(string2);

However, keep in mind you'll need to do a null check on string1 first else you may end up with a NullPointerException. A null-safe version could look like:

boolean match = (string1 == null ? string2 == null : string1.equals(string2));

One more Android-specific alternative is:

TextUtils.equals(string1, string2);
Michael Dodd
  • 10,102
  • 12
  • 51
  • 64