class strb { static public void main(String...string) { StringBuilder s1 = new StringBuilder("Test"); StringBuilder s2 = new StringBuilder("Test"); System.out.println(s1); // output: Test System.out.println(s2); // Test System.out.println(s1==s2); // false System.out.println(s1.equals(s2)); //Line 1 output: false System.out.println(s1.toString()==s2.toString()); //Line 2 output: false } } Just have a quick question on .equals.
Regardless of the object content, does .equals return true only if both the object references point to the same object ?
EDIT : Now I understand the part about the .equals but why does Line 2 not return true ?
EDIT : I believe == looks at the reference variable's address and so s1 and s2 cannot be equal.correct me if my assumption is not right