java - Android: Substring & IF -
this question has answer here:
- how compare strings in java? 23 answers
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
Post a Comment