• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When The default value of "StringBuffer" is fill?

 
Danish
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question :
When The default memory of
String buffre is fill and why Stringbuffer has default memory and when and why it is uesful for us .
plz reply as soon as possible
Thanksu
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Danish,
Before I attempt to answer your question, let me say that you're probably going to have a bartender ask you to change your display name to a first and last name as per the naming policy here at JavaRanch.
Now, I'm not real sure what your asking about StringBuffer, but it is an extremely useful class. As you probably already know, String's are immutable. StringBuffers are essentially "mutable" Strings. As a matter of fact the JAVA platform uses StringBuffers behind the scenes to concatenate (add) Strings. For instance when you code something like this:

The compiler converts all of this into a StringBuffer, sticks the parts together and finally returns a String. You can do the same thing like this:

Hope this helps
Michael Morris
SCJP2
 
Danish
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
U DID NOT UNDERSTAND MY QUESTION;
my question is that the Stringbuffer has default more memory about 16 and if we create an object in stringbuffer will occupies memory
memory=object in stringbuffer + 16(default value of stringbuffer)
thanking for reply me and plz repiy me again to this question
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again Danish,
Ok, let's take another crack at this. Are you asking why SUN in it's infinite wisdom decided to allocate a default buffer with a 16 char capacity?
If that's your question, I have no earthly, freakin' idea, but I suspect it went something like this:
System engineer dude 1:
"Hey Joe how may char's should the initial buffer in StringBuffer hold?"
System engineer dude 2:
"Gee Harry, I don't know. Let me do some performance testing and I'll get back with you on that."
.....
Two weeks later
System engineer dude 2:
"Hey Harry, I've got that data back on the initial buffer size for StringBuffers." It looks like somewhere around 13 characters gets the best performance."
System engineer dude 1:
"O, thanks Joe. What do you say we set it at 16 always best to use a power of 2 don't you think?"
System engineer dude 2:
"You bet. 13 would make us look like a bunch of Microsoft engineers."
I hope that answers your question.
Now if the default is a problem, you can set the initial buffer to whatever you want with:

Hope this helps :roll:
Michael Morris
SCJP2
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Danish,

Before I attempt to answer your question, let me say that you're probably going to have a bartender ask you to change your display name to a first and last name as per the naming policy here at JavaRanch.

U DID NOT UNDERSTAND MY QUESTION

Did you understand Michael's statement? You were asked very politely to please change your display name. :roll:
 
Danish
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thaku
you have been success to understand me about my stringbuffer thaku for that answer , if u dont mind then plz send the email address of u that i will contact u
my emailadress is "Danishnajam84@hotmail.com"
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Danish,
Hey dude, you really do need to change your display name to a first and last name before Marilyn sends a posse out after you and we have a lynchin' here at the Ranch.
Any way my email is:
mike@m2squared.com
If you look on my posts on this thread, there are several icons at the top. I think the third one is email. So if you want to get in touch with anyone here that posts that's where you'll find their emails.
Hope this helps
Michael Morris
SCJP2
[ March 24, 2002: Message edited by: Michael Morris ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic