Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string buffer

 
Sagar
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class test1
{
static public void main(String args[])
{
String sb1 = new String("Amit");
String sb2= new String("Amit");
String ss1 = "Amit";
System.out.println(sb1==sb2);//false,
System.out.println(sb1.equals(sb2));//true
System.out.println(sb1.equals(ss1));//true
}
}

class test1
{
static public void main(String args[])
{
StringBuffer sb1 = new StringBuffer("Amit");
StringBuffer sb2= new StringBuffer("Amit");
String ss1 = "Amit";
System.out.println(sb1==sb2);//false
System.out.println(sb1.equals(sb2));//false
System.out.println(sb1.equals(ss1));//false
}
}
Is the output as expected in case of string buffer??

please explain..i am

thanks
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you check the API, you'll see that StringBuffer does not override the equals method, so it invokes the method as defined in Object (which is basically ==).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic