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

Tosin Adedoyin
Ranch Hand

Joined: Nov 09, 2001
Posts: 43
class Mock
{
public static void main(String args[]) {
StringBuffer sb1 = new StringBuffer("Amit");
StringBuffer sb2= new StringBuffer("Amit");
String ss1 = "Amit";
System.out.println(sb1==sb2);
System.out.println(sb1.equals(sb2)); // line 2
System.out.println(sb1.equals(ss1));
System.out.println("Poddar".substring(3));
}
}
why does line 2 print false instead of True
luco zhao
Ranch Hand

Joined: Apr 23, 2002
Posts: 50
Originally posted by Tosin Adedoyin:
class Mock
{
public static void main(String args[]) {
StringBuffer sb1 = new StringBuffer("Amit");
StringBuffer sb2= new StringBuffer("Amit");
String ss1 = "Amit";
System.out.println(sb1==sb2);
System.out.println(sb1.equals(sb2)); // line 2
System.out.println(sb1.equals(ss1));
System.out.println("Poddar".substring(3));
}
}
why does line 2 print false instead of True

Because StringBuffer class doesn't override equals() method, not expected as String class which overrides equals() method.


Great thanks,<br />Luco Zhao
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String buffer
 
Similar Threads
stringbuffer equals
String Q
equals and ==
string buffer
equals with stringbuffer