java - why is string matching not working? -


this question has answer here:

 string [] p = k.split(" "); //nb: value of k "malaria zika aids"   (int x=0;x< p.length; x++)     {        if (p[x]=="zika")            {              system.out.println( "this zika virus p[x]="+ p[x]);                 }else{            system.out.println( "this not zika virus p[x]="+p[x]);            }    } 

expecting

this not zika virus p[x]=malaria zika virus p[x]=zika not zika virus p[x]=aids 

but getting

this not zika virus p[x]=malaria not zika virus p[x]=zika not zika virus p[x]=aids 

what missing? believe part problem. if (p[x]=="zika")

change line

if (p[x]=="zika")  if(p[x].equals("zika") ) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -