Recently in an interview I was asked the following question (for Java):
Given:
String s1 = "abc"; String s2 = "abc";
What is the return value?
(s1 == s2)
I replied that it would return false, because these are two different objects, and == is a comparison of memory addresses, not a comparison of values, and that you need to use .equals () to compare String objects. I was told that although .equals (0 methodology was correct, the statement nonetheless returns true. I was wondering if anyone could explain this to me why this is true, but why we are still learning how to use equals at school ()
source share