Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Number of objects created in StringBuilder ?

 
Lovleen Gupta
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know -- if it had been string here like ::
String s = new String("abc");
2 objects are created.

But, how many objects are created when we say --

StringBuilder sb = new Stringbuilder("abc");

Thanks.
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo,

When using StringBuffer, the case is one-by-one, meaning, one object and one reference.

So, when we say:



There will be this one object on the heap with stringBuffer referring to it.

Good luck ...
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry i forgot to say that StringBuffers don't go to the String constant pool.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic