+ 1

How to compare Strings in Android Java?

I am trying to compare strings like this if(var1==var2). but it's not working. i also tried var1.compareTo(var2) but no success.

8th Mar 2017, 1:50 PM
Zain Khalid
Zain Khalid - avatar
9 odpowiedzi
+ 2
check for equality
8th Mar 2017, 4:00 PM
Zain Khalid
Zain Khalid - avatar
+ 2
and also how can we parse int from string at compare it to other string variable? in my case i used. Integer.parseInt(var); that raised exception
8th Mar 2017, 5:42 PM
Zain Khalid
Zain Khalid - avatar
+ 1
What? yoy want to compare or check for eqaulity?
8th Mar 2017, 3:16 PM
Meharban Singh
Meharban Singh - avatar
+ 1
equals()
8th Mar 2017, 3:44 PM
Barra
Barra - avatar
+ 1
if(var1.equals(var2){ //do something }
8th Mar 2017, 4:01 PM
Barra
Barra - avatar
+ 1
U can check for equality in 2 ways. if(var1==var2) OR. if(var1.equals(var2) However ,there is a slight difference between the two.
8th Mar 2017, 5:40 PM
Meharban Singh
Meharban Singh - avatar
+ 1
what is the difference between them.
8th Mar 2017, 5:41 PM
Zain Khalid
Zain Khalid - avatar
0
To convert String to int:- Integer.parseInt(var); To convert int to String :- var.toString();
8th Mar 2017, 5:44 PM
Meharban Singh
Meharban Singh - avatar
0
U ppl r so smart
13th Mar 2017, 3:57 AM
Maria