-1

As a condition, I am equating two variables String a and String b. They are exactly the same, in fact I printed the values to the logcat and they are the same string, no extra spaces. But whenever I equate them (a == b), I am getting false back. I even printed out the value with

Log.v("BOOLEAN", Boolean.toString(a == b));

And I got false back. Though when I print out the values sandwiched between the letters I (to make sure there weren't spaces on the end messing the string up), I get

V/BOOLEAN: I123I123I

This is the relevant code

user_pin = USER_PIN.getText().toString();

    DatabaseOperations DOP = new DatabaseOperations(ctx);
    DOP.open();
    Cursor CR = DOP.getRow(id);
    CR.moveToFirst();
    user_pin_database = CR.getString(3);

    Log.v("BOOLEAN", "I" + CR.getString(3) + "I" + user_pin + "I");

    if (user_pin == user_pin_database) {...}

Does anyone know what's causing this?

Alex
  • 325
  • 7
  • 16

1 Answers1

2

(==) compares references of two string objects in java. You should use .equals() method or .equalsIgnoreCase() to compare contents of two strings.

Stormbuster
  • 76
  • 2
  • 12