File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Does StringBuffer overrides equals()!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Does StringBuffer overrides equals()!!" Watch "Does StringBuffer overrides equals()!!" New topic

Does StringBuffer overrides equals()!!

natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
Just want to make sure whether the StringBuffer class overrides the equals() method of the Object class.
I say no. It doesn't override it.
StringBuffer sb1 = new StringBuffer("Amit");
StringBuffer sb2= new StringBuffer("Amit");
sb1.equals(sb2) returns false.

Sun Certified Programmer for Java 2 Platform
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
yes it doesn't overwride it.

Val SCJP <BR>going for SCJD
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
Val is right. You really should consult the documentation for questions like this. It'll help you in the long run, if you familiarize yourself with the apis.
Shrini Kulkarni
Ranch Hand

Joined: Jan 12, 2001
Posts: 63
StringBuffer class doesnot override equals(). That is when we use equals() for StringBuffers, what is done is just reference comparasion - the behaviour inherited from Object class. Boolean and String classes override equals() method. Thus when two strings are compared - comparison is done for equality of string contents not thier handles.

Sun Certified programmer for Java2 platform.<BR>
I agree. Here's the link:
subject: Does StringBuffer overrides equals()!!
It's not a secret anymore!