如果阻止无法识别字符串

Too*_*ink -1 java if-statement

for (int i = 0; i< expArray.length; i++){
            System.out.println(expArray[i]);
            if ( expArray[i] == "5" ){  ///WHY IS THIS NOT WORKING!!!??             
                System.out.println("here");
Run Code Online (Sandbox Code Playgroud)

我知道输出System.out...:

0
=
0
+
5
Run Code Online (Sandbox Code Playgroud)

这是我的String阵列的制作方式:

    for (int i = 0; i< expArray.length; i++){
        if(varTable.get(expArray[i]) != null){
            expArray[i] =  Integer.toString((int) varTable.get(expArray[i]));
        }
    }
Run Code Online (Sandbox Code Playgroud)

所以问题是,在expArray[i] == "5" )if block up up它不会进入i=1它应该的位置.任何理由/想法?

Ale*_* K. 5

如果您有常量,请使用nullsafe检查

if("5".equals(expArray[i]))
Run Code Online (Sandbox Code Playgroud)