File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String buffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String buffer" Watch "String buffer" New topic
Author

String buffer

Kalpesh Pandya
Greenhorn

Joined: Oct 07, 2000
Posts: 14
I came across following question in one of the mock exam.
StringBuffer sb1 = new StringBuffer("xyz");
StringBuffer sb2= new StringBuffer("xyz");
String ss1 = "xyz";
System.out.println(sb1==sb2);
System.out.println(sb1.equals(sb2)); // 2nd
System.out.println(sb1.equals(ss1)); //3rd
Answer is false, false, false.
Anybody would help me out why 2nd and 3rd comparison results in false ?
mailssk
Greenhorn

Joined: Oct 10, 2000
Posts: 6
StringBuffer does not override equals() method and hence returns false
Originally posted by Kalpesh Pandya:
I came across following question in one of the mock exam.
StringBuffer sb1 = new StringBuffer("xyz");
StringBuffer sb2= new StringBuffer("xyz");
String ss1 = "xyz";
System.out.println(sb1==sb2);
System.out.println(sb1.equals(sb2)); // 2nd
System.out.println(sb1.equals(ss1)); //3rd
Answer is false, false, false.
Anybody would help me out why 2nd and 3rd comparison results in false ?

Kalpesh Pandya
Greenhorn

Joined: Oct 07, 2000
Posts: 14
Thanks !! Its clear now.
Sandeep Lodhia
Ranch Hand

Joined: Oct 09, 2000
Posts: 105
Hi Kalpesh'
There is no method like equals()in StringBuffer class.:rolleyes kidding).Hence it will always return false
Sandeep.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: String buffer
 
Similar Threads
equals with stringbuffer
String Q
String manipulation
string buffer
string buffer