aspose file tools
The moose likes Java in General and the fly likes equals() in StringBuffer Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "equals() in StringBuffer" Watch "equals() in StringBuffer" New topic
Author

equals() in StringBuffer

Chinmay Bajikar
Ranch Hand

Joined: Dec 08, 2001
Posts: 159
Hi,
Have a look at this code snippet,



What should ideally happen?
I didnt find any equals() implementation in the StringBuffer class.
I am using JDK 1.4.2.


The strength of the Wolf is the pack & the strength of the pack is the wolf....Rudyard Kipling
Chinmay Bajikar
Ranch Hand

Joined: Dec 08, 2001
Posts: 159
Sorry, but I should have serached the forum for similar topics first.
Found what I was looking for here,
Answer

Was curious to know if there is any specific reason for not overriding equals() in StringBuffer.

Thanks and sorry for the inconvinience,
Chinmay.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24059
    
  13

I would imagine it was just an oversight. Remember the curious fact that the oldest classes in the Java APIs were written by people who had no experience at all writing in Java!


[Jess in Action][AskingGoodQuestions]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Ernest Friedman-Hill:
I would imagine it was just an oversight. Remember the curious fact that the oldest classes in the Java APIs were written by people who had no experience at all writing in Java!


And apparently also not in other OO languages... :roll:


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
but StringBuilder (added in 1.5) also does not override equals()...

any other reasons (appart from "just forgotten") ?

cheers

pascal
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by pascal betz:
but StringBuilder (added in 1.5) also does not override equals()...


They probably wanted it to be as compatible to StringBuffer as possible...
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5082260 explains it all.
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
who needs Map anyway :-)

thanks for the link.

pascal
bala rajesh
Greenhorn

Joined: Jul 31, 2006
Posts: 6
Originally posted by Chinmay Bajikar:
Hi,
Have a look at this code snippet,



What should ideally happen?
I didnt find any equals() implementation in the StringBuffer class.
I am using JDK 1.4.2.



Answer
------


== symbols used to compare the content(string)in a object.
but .equals()method is used to compare the string or stringbuffer object;
so sbuf,dbuf or different object, so that the result is sbuf!=dbuf
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by bala rajesh:
== symbols used to compare the content(string)in a object.
but .equals()method is used to compare the string or stringbuffer object;
so sbuf,dbuf or different object, so that the result is sbuf!=dbuf


Huh? For StringBuffer objects, == and equals() do exactly the same thing, because StringBuffer doesn't override equals() (in contrast to String). The original poster asked about the reasoning for this, and I think the previous responses were right on mark. Therefore your responses confuses me quite a bit...
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: equals() in StringBuffer
 
Similar Threads
equals method in String Class
StringBuffer exam q
StringBuffer
StringBuffer and equals() method overriding
General code to resolve String/StringBuffer doubt