• Post Reply Bookmark Topic Watch Topic
  • New Topic

string buffer  RSS feed

 
Greenhorn
Posts: 14
  • 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
 
Sheriff
Posts: 11343
Java Mac Safari
  • 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 ==).
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!