This question already has an answer here:
- How do I compare strings in Java? 23 answers
this is a basic knowledge but I get frustrated after 3 hours of trying. I am running codes in Android Studio and I just want to compare the result of 2 strings This is my codes
result=stringBuilder.toString();
String wanted="SUCCESS";
if(result.equalsIgnoreCase("SUCCESS"))
{
Log.d("RESULT","FINALLY 1");
}
else if(result.equals("SUCCESS")) {
Log.d("RESULT", "FINALLY 2");
}
else if(result=="SUCCESS")
{
Log.d("RESULT","FINALLY 3");
}
else if("SUCCESS".equals(result))
{
Log.d("RESULT","FINALLY 4");
}
else if(result.equals(wanted))
{
Log.d("RESULT","FINALLY 5");
}
else
{
Log.d("RESULT",result);
}
I have tried every options available on webs but I got the same results and you can see that var "result" is "SUCCESS"
11-11 23:31:01.477 8116-8152/com.example.asus.ucomm D/RESULT﹕ SUCCESS
What did I do here that get errors from just comparing strings? Am I too tired until I missed something? Please help.
Aucun commentaire:
Enregistrer un commentaire