Why Is My String To String Comparison Failing?
I have an Android app where I want to check to see if an app name that is installed matches a string passed to the function containing this code. The code and example is below: pri
Solution 1:
Use the String's equals() method instead of the == operator for comparing strings:
info.activityInfo.applicationInfo.loadLabel( pm ).toString().equals(appName)
In Java, one of the most common mistakes newcomers meet is using ==
to compare Strings. You have to remember, ==
compares the object references, not the content.
Solution 2:
Solution 3:
publicstaticboolean compaireString (Stringstring, String string2)
{
// string == null && String2 == null or they reference the same objectif (string == string2) returntrue;
//we have to be sure that string is not null before calling a methode on itif (string != null && string.equals(string2)) returntrue;
returnfalse;
}
Post a Comment for "Why Is My String To String Comparison Failing?"