Re: How equals method works in StringBuffer?



<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
.



Relevant Pages

  • Re: JDBC compare the content of two tables
    ... I want to use getObject method to get the value of each column, ... then use equals method of java.lang.Object to compare two columns' values. ... representation for NaN or not. ...
    (comp.lang.java.help)
  • Re: Newbie question about object comparisons
    ... > However, in the business problem I'm trying to solve, the 'keys' are ... In that case I amend my recommended solution: use the Equals method. ... the correct Equals to call to compare your two keys. ...
    (microsoft.public.dotnet.csharp.general)
  • Re: Sorting arrays (again)
    ... It just tells you that though the compilation went through, ... javac command to uncheck -Xlint? ... To what am I supposed to compare? ... And now I can implement the equals method as well. ...
    (comp.lang.java.help)
  • Re: flyweight object equivalence
    ... I'm running up against a subtlety, namely I am not sure how to provide ... the functionality for testing equality. ... If I wanted to compare this information in C++, ... you would have to provide an Equals method on one of the interfaces they ...
    (microsoft.public.vc.atl)
  • Re: implicitly handle operator == when class overrides Equals method
    ... operators when my class overrides the Equals method and implements the ... Then compare for equality. ... object obj1 = InFac1; ... object obj2 = InFac2; ...
    (microsoft.public.dotnet.languages.csharp)