aspose file tools*
The moose likes Beginning Java 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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string buffer" Watch "string buffer" New topic
Author

string buffer

Sagar
Greenhorn

Joined: Mar 25, 2005
Posts: 14
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


Sagar
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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 ==).


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: string buffer
 
Similar Threads
String buffer
Equal(),==
string(buffer) comparision...
String Q
String and StringBuffer