Originally posted by Roger Chung-Wee:
Note that the equals method is overridden in the String class but inherited in the StringBuffer class.
True. I have been caught out by that. If you look through the API documentation for StringBuilder you find "equals" in the block headed "inherited from Object" and in String you find the method in amongst all the other methods. That is how you can tell.
I enquired more about that, and found that Sun are of the opinion that something which changes all the time, like a StringBuilder (use StringBuilder instead of StringBuffer) ought not to have its own equals method. I am not convinced, but you can use
if(builder1.toString().equals(builder2.tostring()) . . .