-1

I have a weird problem... I use this code:

    String text = new String(values[0]);
    Log.e("TEST", "|" + text + "|" + new String(values[0]) + "|");
    if (text == "pong") {
        Log.e("TEST", "2|" + new String(values[0]) + "|");
        receivedresponse = true;
    } else {
        Log.e("TEST", "1|" + new String(values[0]) + "|");
        myToast.setText(new String(values[0]));
        myToast.show();
    }

values = 112,111,110,103

String(values[0]) = "pong"

text = new String(values[0]) = "pong"

still text != "pong"... however "pong" == "pong"?

-

Anyone knows why?

Mat
  • 202,337
  • 40
  • 393
  • 406
Marco
  • 368
  • 1
  • 4
  • 16
  • text.compareTo("pong") seemed to work! Any idea why it has to be this way? I did like to learn :) – Marco May 14 '12 at 20:11
  • 4
    You have .equals() in java. do not use ==. Take a look at this: http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java – superM May 14 '12 at 20:12
  • Thanks! Usefull information, should have answered instead... – Marco May 14 '12 at 20:16

1 Answers1

6

In java you need to use .equals on the string:

   text.equals("pong");
Nick
  • 6,375
  • 5
  • 36
  • 53