This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String buffer