Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Want the difference between String and StringBuffer  RSS feed

 
sharon daze
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all ,

String s = "abc";
String s2 = new String("abc");

if(s==s2) // this is true

then

String s = "abc";
String s2 = new StringBuffer("abc").toString();
if(s==s2) // this condition will be false

What is the difference between this two codes.



 
Henry Wong
author
Sheriff
Posts: 22848
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String s = "abc";
String s2 = new String("abc");

if(s==s2) // this is true



Really?!?!? This is true? .... I don't think this is true.

Henry
 
Henry Wong
author
Sheriff
Posts: 22848
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String s = "abc";
String s2 = new StringBuffer("abc").toString();
if(s==s2) // this condition will be false


This is false because the toString() method of the StringBuffer class will return a new String.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!