aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes equals() in StringBuffers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "equals() in StringBuffers " Watch "equals() in StringBuffers " New topic
Author

equals() in StringBuffers

KN
Ranch Hand

Joined: Aug 13, 2000
Posts: 66
Hi!
Can anybody please help me with this topic. Here is the code
StringBuffer sb1 = new StringBuffer("abc");
KN
Ranch Hand

Joined: Aug 13, 2000
Posts: 66
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

Joined: Jun 13, 2000
Posts: 3340
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.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
KN
Ranch Hand

Joined: Aug 13, 2000
Posts: 66
Thanks Carl.
Are there any classes other than String & Wrapper classes which override equals() method?
KN
KN
Ranch Hand

Joined: Aug 13, 2000
Posts: 66
Any taker of my above Question?
Thanks
KN
satish
Greenhorn

Joined: Jul 03, 2000
Posts: 27
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


satish
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
KN
Ranch Hand

Joined: Aug 13, 2000
Posts: 66
Ajith,
Where can I find the Java API Documentation?
Thanks
KN
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: equals() in StringBuffers