Re: How equals method works in StringBuffer?
- From: Patricia Shanahan <pats@xxxxxxx>
- Date: Thu, 31 Aug 2006 13:50:51 GMT
Jeffrey Schwab wrote:
Chris Smith wrote:<swornavidhya_m@xxxxxxxxxxx> wrote:Hai,
In my following code, the output i obtained is: false. Whereas
my expectation for output is true. I need ur suggestions and ideas.
StringBuffer's equals method returns true only when a StringBuffer object is compared with itself. It returns false when compared with any other StringBuffer, even if the two contain the same characters. This is actually quite a sensible behavior.
Chris, would you mind elaborating a little? I would have expected:
sb1.equal(sb2) == sb1.toString().equal(sb2.toString())
The API documentation for StringBuffer lists "equals" as a method
inherited from Object, so I expect the same behavior as the Object
equals method.
Maybe it was done that way because you can always write
sb1.toString().equals(sb2.toString()) if that is what you mean.
Patricia
.
- References:
- How equals method works in StringBuffer?
- From: swornavidhya_m
- Re: How equals method works in StringBuffer?
- From: Chris Smith
- Re: How equals method works in StringBuffer?
- From: Jeffrey Schwab
- How equals method works in StringBuffer?
- Prev by Date: Re: Unescaping Unicode code points in a Java string
- Next by Date: Re: How equals method works in StringBuffer?
- Previous by thread: Re: How equals method works in StringBuffer?
- Next by thread: Re: How equals method works in StringBuffer?
- Index(es):