October 2004
Intermediate to advanced
624 pages
16h 2m
English
A well-known inefficiency in Java [Larm2000] is in string concatenation. The way around it is to ensure that the concatenation is done within a single statement, which facilitates a compiler optimization in which the successive arguments to the + operator are silently translated into calls to a hidden StringBuffer instance, resulting in a more efficient construction of the string from its constituent parts. Hence,
String s = s1 + " " + s2 + " " + s3;
is automatically converted to
StringBuffer sb = new StringBuffer();
sb.append(s1);
sb.append(" ");
sb.append(s2);
sb.append(" ");
sb.append(s3);
String s = sb.toString();
This results in significant increases in performance [Wils2003e] compared ...
Read now
Unlock full access