java - Android: Substring & IF -


this question has answer here:

i have problem following code. cut string "data1", give "data2" , check string. phone says "ab not ab", not know why? -.-

any ideas?

string data1 = "abc"; string data2 = "";  data2 = data1.substring(0, 2);  if(data2 == "ab")   {         toast.maketext(this, data2 + " ab" , toast.length_long).show();   } else   {         toast.maketext(this, data2 + " not ab", toast.length_long).show();    } 

thanks ...

in java compare strings using method equals(). more info here

change if statement follows

if(data2.equals("ab")) {     toast.maketext(this, data2 + " ab" , toast.length_long).show(); } else {     toast.maketext(this, data2 + " not ab", toast.length_long).show();  } 

Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -