I am reading some notes about how to compare equality between String in Java.
String s1 = new String("abc");
String s2 = new String("abc");
These two are allocated in different memory, so their reference are different. When we call
if (s1 == s2){ .. } // Comparing the reference, so return false
if(s1.equal(s2)){..} // Comparing content, so return true
So, what is
String s3 = "abc"
String s4 = "abc"
?
How is the memory allocated and when I do different equality check, what will happen?
For example :
s3==s4
s3.equal(s4)
s3.equal(s1)