HI EVERYBODY This is nivvi, i am new to this. I have doubt regarding strings and stringbuffers.can i use srtingbuffers instead of strings?if so, then which performance is better ?i mean working with strings is better one or stringbuffer is better one for increasing the performance of the progam.
Tony Smith
Ranch Hand
Joined: Jul 07, 2007
Posts: 229
posted
0
You posted in the wrong forum. Please read the rules first. Use strings, unless you have reason to use stringbuffer.
There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
I think the answer to your question, like most software issues, is "it depends".
it depends on HOW you are using the objects, and WHAT you are doing with them. There are situation where one is perferable over the other, and vice versa.
Never ascribe to malice that which can be adequately explained by stupidity.
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
posted
0
As others have said already, String and StringBuffer are quite different, so there are not all that many situations where you could actually swap one for the other.
The reason for preferring StringBuilder is that it is not encumbered with pointless synchronisation. Very few uses of StringBuffer actually made use of its synchronisation, but all suffered the performance costs of it.
As a beginner, you don't really need to understand the paragraph above. Just remember that, if you are writing for Java 5 or newer, use StringBuilder.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P