There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
"I'm not back." - Bill Harding, Twister
Originally posted by Adam Schaible:
This would fall into the lines of premature optimization - especially considering the IBM 1.5 compiler will do it automatically anytime you have string + string.
Sun introduced the StringBuilder class in J2SE 5.0, which is almost the same as StringBuffer, except it's not thread-safe. Thread safety is usually not necessary with StringBuffer, since it is seldom shared between threads. When Strings are added using the + operator, the compiler in J2SE 5.0 and Java SE 6 will automatically use StringBuilder. If StringBuffer is hard-coded, this optimization will not occur.
Joanne
"I'm not back." - Bill Harding, Twister
Originally posted by Joanne Neal:
[ November 09, 2007: Message edited by: Joanne Neal ]
"I'm not back." - Bill Harding, Twister
I think that's unlikely. The concatenation may degrade performance by creating a lot of temporary extra objects, but those objects should all available for garbage collection. If you're getting OutOfMemoryError, it's because something cannot be collected. You probably need to look elsewhere.
"I'm not back." - Bill Harding, Twister
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|