What's wrong with == operator on java string -
this question has answer here:
- how compare strings in java? 23 answers
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
Post a Comment