java - Cell of a String array and String doesn't match -


here's java code:

string s="foo";  for(int i=0;i<5;i++) if(myarray[i]==s) return true; 

by debugging, i'm sure first element of myarray same string s, doesn't match, because program jump on if block(the condition false). there can me?

you should use string.equals() compare types of string.

if(myarray[i]==s) 

should be

if(myarray[i].equals(s)) { } 

at moment, you're testing if s , myarray[i] same object, not different objects containing same value.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -