+ 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.
9 Answers
+ 2
check for equality
+ 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
+ 1
What? yoy want to compare or check for eqaulity?
+ 1
equals()
+ 1
if(var1.equals(var2){
//do something
}
+ 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.
+ 1
what is the difference between them.
0
To convert String to int:-
Integer.parseInt(var);
To convert int to String :-
var.toString();
0
U ppl r so smart