This question already has an answer here:
- How do I compare strings in Java? 23 answers
Why below s3
and s5
String
objects are differ, When s5
try to created in String pool it checks content s3
already have same content so s5
refers s3
object in string pool. But my assumption is wrong, then any one correct me.
String s1="Buggy";
String s2="Bread";
String s3="BuggyBread";
String s4 = "Buggy"+"Bread";
String s5 = s1 + s2
System.out.println(s3==s4); // True
System.out.println(s3==s5); //false