Re: How equals method works in StringBuffer?
- From: Chris Smith <cdsmith@xxxxxxx>
- Date: Thu, 31 Aug 2006 00:43:01 -0600
<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. However, the meaning of equals
is unfortunately not defined very well, and it is inconsistently used
across the Java API, so this is a bit confusing.
To compare the String objects that are produced by the StringBuffer
objects in their current state, use s1.toString().equals(s2.toString())
instead.
--
Chris Smith
.
- Follow-Ups:
- Re: How equals method works in StringBuffer?
- From: Jeffrey Schwab
- Re: How equals method works in StringBuffer?
- References:
- How equals method works in StringBuffer?
- From: swornavidhya_m
- How equals method works in StringBuffer?
- Prev by Date: How equals method works in StringBuffer?
- Next by Date: Unescaping Unicode code points in a Java string
- Previous by thread: How equals method works in StringBuffer?
- Next by thread: Re: How equals method works in StringBuffer?
- Index(es):
Relevant Pages
|