Programming in
Java for over 1-1/2 years now, I have picked up this impression that
String x = y+z; will be slower than a StringBuffer.append. I dont know why but it was a strong conviction I had
but today for the first time when I had to proove this to someone and I ran a BenchMark
test where I did something like
for(20000 times){
String s = a+"~"+b+"~"+c+...4 to 5 more strings
clear s
}
and
for(20000 times){
stringbuffer.append(a);
stringbuffer.append("~");
.
.
.
create a new String from buffer
}
I found the latter to be much slower
Even more surprise though string.concat() performed better than the buffer it was still a tad slower than the one that used "+"
So is using "+" to append string the fastest way after all
-Rajagopal
[ January 06, 2006: Message edited by: Rajagopal Manohar ]