java - why is string matching not working? -
this question has answer here:
- how compare strings in java? 23 answers
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
Post a Comment