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

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -