Local database reading edition
How to use StringBuffer “Efficiently”?
Reconstructed from database records, not a captured original forum layout. Dates and display names are retained as recorded; timezone and real-world identity are not inferred. Historical advice, contact details and offers are not current. Original markup is shown as inert text.
Forum index · Java - Tips Of The Day
Opening post
Asha · 2001-02-13 13:20:05
In this tip I thought of focusing on how to use Java API efficiently to
improve the performance. As many of us know that “String concatenation via
the "+" operator is one of the most convenient things to do in Java”. It is
also one of the most expensive, in terms of memory and performance if we do
not use it properly.
The useful tip we found almost all java performance enhancement article is
use String- Buffer to concatenate Strings like
StringBuffer temp = new StringBuffer( );
temp.append(“My name is Asha”);
temp.append(“I am a Java Develpoer “);
temp.append(myString); -àmyString would be holding of a big Text
temp.toString();
Here is the whole point when the StringBuffer Object is constructed the
size of the buffer is ALWAYS set to 16 characters so there is Absolutely no
benefit of StringBuffer rather more overhead in doubling the buffer size
and copying the Old data .
I would suggest, initialize approximate size at the Construction of StringBuffer which would give us the real performance.
StringBuffer temp = new StringBuffer(400 ); -> this is the deal
temp.append(“My name is Asha”);
temp.append(“I am a Java Develpoer “);
temp.append(myString); ->myString would be holding of a big Text
temp.toString();
Asha Balasubramanyan
http://www.ammu.org
Source notes
MyCommunity/nandighosha.org.zip!/forum/tools/snitz_forums_2000.mdb
Table: FORUM_TOPICS + FORUM_REPLY · record IDs: 19