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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -