为什么字符串匹配不起作用?

时间:2016-02-06 08:45:27

标签: java string comparison

 String [] P = K.split(" ");
//NB: the value of K is "malaria zika AIDS"

 for (int x=0;x< P.length; x++) 
   {
       if (P[x]=="zika") 
          { 
            System.out.println( "This is zika virus P[x]="+ P[x]); 
               }else{
           System.out.println( "This is NOT zika virus P[x]="+P[x]); 
          }
   }

期待

This is NOT zika virus P[x]=Malaria
This is zika virus P[x]=zika
This is NOT zika virus P[x]=AIDS

但是获得

This is NOT zika virus P[x]=Malaria
This is NOT zika virus P[x]=zika
This is NOT zika virus P[x]=AIDS

我错过了什么?我相信这是问题的一部分。 if (P[x]=="zika")

1 个答案:

答案 0 :(得分:0)

更改此行

myPopup.close();