String Operations Java is a young language and it's hard to say for sure just how some of the performance aspects of the language will shake out. But we will offer from time to time some performance tips that may be useful.
Many performance techniques apply in any programming language.
It takes about 13 seconds using JDK 1.0 on a Pentium. When we profile the program, we find that it seems to be doing lots of data shuffling and so forth, with the garbage collector called 40 times. To append to a String you must copy out the String to a StringBuffer and append to it and then convert it back. Note that we captured the old value of ss before ss was changed to point to a new String. The old String didn't change when we reassigned ss, we just changed a reference that pointed at it to point at a new String.