class Test { public static void main(String...args) { String s1 = \"Good\"; s1 = s1 + \"morning\"; System.out.println(s1.intern());
You need to use s1.equals(s2). Using == with String objects compares the object references themselves.
s1.equals(s2)
==
String
Edit: When I run your second code snippet, I do not get "both are equal" printed out.
Edit2: Clarified that references are compared when you use '=='.