I have a question about proper use of StringBuffers. According to the API documentation, when you don't really know how many characters are going to wind up in your StringBuffer, you can construct it a couple of ways. You can create an empty StringBuffer with an initial capacity of 16 characters:
StringBuffer sb = new StringBuffer();
..or you can create a StringBuffer with no characters and an intitial capacity specified by an integer:
StringBuffer sb = new StringBuffer(1000);
Now, if you know your going to need > 16 characters, but aren't sure what the exact amount's going to be, is it better (performance wise) to go ahead guesstimate an amount? What if you over-estimate? Like in my example above, what (if any thing) is the down side to creating it with an initial capacity of 1000 and only using half the characters? What if you under-estimate? Is that a bad thing?
Everywhere that I've read about optimizing
Java's performance mentions something about being extra careful with
String manipulation. I'd like to know as much as possible the top things to look for in making my Java app's run as efficently as possible. The 20% that I can do to make 80% worth of difference.
Thanks,
Rick