What's wrong with == operator on java string -


this question has answer here:

i have,
string str1 = "stringa";
string str2 = "stringa";

now, do

(str1 == str2)

sometimes doesn't match strings , returns false

but str1.equals(str2) returns true

what i'm missing here?
cannot use equals string can null also.

thanks!

== compares references not content

to compare strings need use string#equals:

.equals(); //if  consider case .equalsignorecase(); //if not consider case   

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -