Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

equals() in StringBuffers

 
KN
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Can anybody please help me with this topic. Here is the code
StringBuffer sb1 = new StringBuffer("abc");
 
KN
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Sorry for that incomplete message!
Can anybody please help me with this topic. This code returns false but I don't understand why?
StringBuffer sb1 = new StringBuffer("abc");
StringBuffer sb2 = new StringBuffer("abc");
System.out.println(sb1.equals(sb2));
Is there any example, in which equals() method in case of StringBuffer returns true.
Thanks in advance,
KN
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by KN:
Hi!
Sorry for that incomplete message!
Can anybody please help me with this topic. This code returns false but I don't understand why?
StringBuffer sb1 = new StringBuffer("abc");
StringBuffer sb2 = new StringBuffer("abc");
System.out.println(sb1.equals(sb2));
Is there any example, in which equals() method in case of StringBuffer returns true.
Thanks in advance,
KN

StringBuffer sb1 = new StringBuffer("abc");
StringBuffer sb2 = sb1;
System.out.println(sb1.equals(sb2));
StringBuffer doesn't override equals() in Object, so it only test to see if the references refer to the same object.

 
KN
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Carl.
Are there any classes other than String & Wrapper classes which override equals() method?
KN
 
KN
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any taker of my above Question?
Thanks
KN
 
satish
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the other classes, I know of, that override equals method are wrapper classes Boolean, Integer, Float etc.
Date also overrides equals method but it is not required for the exam.
satish
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refeer to Java API Documentation. Switch to index mode and look for equals(Object) signature. There are a few dozen classes which override equals method.
Ajith
 
KN
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajith,
Where can I find the Java API Documentation?
Thanks
KN
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic