Jerret Halter<br /> <br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.<hr></blockquote>
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by Jerret Halter:
It is because StringBuffer does not override the equals(Object o) method from Object. Object's equals(Object b) method looks like this:
So since you created two differnt StringBuffer objects that are not refering to the same thing they will not be equal using equal(Object o).
Jerret Halter<br /> <br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.<hr></blockquote>
"I'm not back." - Bill Harding, Twister
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
"I'm not back." - Bill Harding, Twister
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
Originally posted by Tom Fulton:
Since I'm relatively new here, I don't want to rock the boat too early. But this topic is one of my pet peeves about Java. Can anyone give me a good reason WHY StringBuffer (and, for that matter, StringBuilder) doesn't have an equals method defined? For the very reasons described here (the extra call to toString() needed), having to convert from a StringBuffer to a String in order to test for value equality has always seemed counterintuitive and stupid. Furthermore, StringBuffer has always been used as a mutable String (whether it should be or not), and it's just common sense (to me, anyway) that there be a direct way to test for value equality. So what's the reason?
Tony Morris
Java Q&A (FAQ, Trivia)
Originally posted by Tom Fulton:
Since I'm relatively new here, I don't want to rock the boat too early. But this topic is one of my pet peeves about Java. Can anyone give me a good reason WHY StringBuffer (and, for that matter, StringBuilder) doesn't have an equals method defined? For the very reasons described here (the extra call to toString() needed), having to convert from a StringBuffer to a String in order to test for value equality has always seemed counterintuitive and stupid. Furthermore, StringBuffer has always been used as a mutable String (whether it should be or not), and it's just common sense (to me, anyway) that there be a direct way to test for value equality. So what's the reason?
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|