aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes StringBuffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "StringBuffer" Watch "StringBuffer" New topic
Author

StringBuffer

Arsho, Ayan
Ranch Hand

Joined: Nov 14, 2001
Posts: 60
<code>
will this code always return false
StringBuffer s1 = new StringBuffer("Java");
StringBuffer s2 = new StringBuffer("Java");
System.out.println(s1.equals(s2));
Would appreciate your reply
Thanks
</code>
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
StringBuffer does not override the equals method and thus inherit the equals method of class Object which basically performs a ==. Thus it will return false since you have two
different references to StringBuffer.
Moreover, if you try to compile and run your code you get the answer the same second !
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
[This message has been edited by Valentin Crettaz (edited December 08, 2001).]


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Thomas Bigbee
Ranch Hand

Joined: Nov 29, 2001
Posts: 48
You are correct - the equals method is inherited from the Object class which tests if two object are equal - ie - points to the same object reference - and since StringBuffer is a final class, and inherits the Object.equals method() - you can not override any of its methods.
At least I think I am correct.
Hope that helps, Tom
------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StringBuffer