-1

Possible Duplicate:
How do I compare strings in Java?

i have 2 class, let say a.class and b.class

and i want to send array from a to b using intent, in a.class

Intent intent = new Intent(this,b.class);
intent.putExtra("stringtext", "1");
startActivity(intent);

and in b.class i catch the intent value with this

Intent it = getIntent();
String id = it.getStringExtra("stringtext");

when i try to print id, it give me "1" but when i'm using id in if clause i didnt work, i try this

if(id=="1")
{
 teks.setText("its one");
}
else
{
 teks.setText("not one";
}

how could this happend?

Community
  • 1
  • 1
sephtian
  • 445
  • 2
  • 11
  • 23

1 Answers1

8

Use equals() method to compare string, == compares the reference for Object

Make it

if("1".equals(id))
{
  teks.setText("its one");
}

See

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438