android: String value match another String value using operand == not working?

前端 未结 5 430
生来不讨喜
生来不讨喜 2021-01-16 20:29

Hopefully this is an easy fix, but for the moment is is boggling me (Actionscript programmer new to Java programming).

I have a string variable coming from getExtra

相关标签:
5条回答
  • 2021-01-16 20:43

    "vuqar"=="vuqar" or "vuqar"!="vuqar" not works correct

    You have to use

    if(vuqar.equals("vuqar")){//action}
    

    OR

    if(!"vuqar".equals("vuqar")){//action}
    
    0 讨论(0)
  • 2021-01-16 20:44

    You must not compare strings via ==, but via .equals()

    0 讨论(0)
  • 2021-01-16 20:46

    Use the equals method instead of ==

    0 讨论(0)
  • 2021-01-16 20:51

    You should use equals for Strings on Java.

    2 tips:

    • Add the string you know it isn't null to avoid nullpointers. Ex: "compare".equals(string)
    • Use equalsIgnoreCase() instead of equals if you wish to compare strings and ignore the case differences.
    0 讨论(0)
  • 2021-01-16 21:09

    Strings are Objects, and to do correct Object equality comparisions, you need to use

    dir.equals("content");
    

    or better yet (to avoid possible null pointer exceptions)

    "content".equals(dir);
    
    0 讨论(0)
提交回复
热议问题