Originally posted by Frank Carver: The two StringBuffers don't come out as equal, because StringBuffer just uses the "default" implementation of equals(), which does the same as '==' and directly compares the object references. The two StringBuffers are different objects with different references, so they come out as non-equal.
Originally posted by Hari Gangadharan: I really love this question! The StringBuffer *does* not override Object's "equals" method whereas String do. Hence when you invoke s1.equals(s2), the equals method of Object is invoked. The equals method of Object just does a shallow compare (which essentially is s1 == s2) and returns false! Hope this helps --
[This message has been edited by Johannes de Jong (edited April 06, 2001).]
The JavaRanch forum in intended for discussion of this web site, not questions about Java itself. That's what all the other forums here are for. I'm moving this discussion to Java in General (Beginner).
"I'm not back." - Bill Harding, Twister
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps