The StringBuffer class does not override equals() it uses the one from the Object class. Refer API. The Object equals() method checks for the equality of the references. In your code sb1 and sb2 have different references, therefore the code should compile fine, but return a false, even though the Strings are identical. You can try the following piece of code to check if the references contain identical Strings, . The output will be true.