"String buffers are used by the compiler to implement the binary string concatenation operator +. For example, the code:
x = "a" + 4 + "c"
"is compiled to the equivalent of:
x = new StringBuffer().append("a").append(4).append("c")
.toString()
"which creates a new string buffer (initially empty), appends the string representation of each operand to the string buffer in turn, and then converts the contents of the string buffer to a string. Overall, this avoids creating many temporary strings."
I haven't actually tested if this is true however, so I don't doubt you that actual compilers really don't do this.
@D
At 04:29 PM 1/20/2003 -0800, Greg Nudelman wrote:
[...]
Actually, if you read the StringBuffer API carefully, you'll note that the compiler "has the option" to optimize String object concatenation. Actually, as the author of the original post (and my own studies) indicated, what most compilers (most unfortunately) do is concatenate only 2 strings at a time. Thus the overwhelming time/system resources needed to append lots of String objects in a loop.
[...]
David Gallardo | Software consultant | Author Java, C/C++ software development | Database development | Internationalization Author of "Java Oracle Database Development" ____________________________________________________ To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm Be respectful! Clean up your posts before replying ____________________________________________________
