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 - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -