Error Case
The heavy use of string concatenation in loops can result in unnecessary memory consumption and frequent garbage collection. Error Analysis
Wrong wording:
String str = "";
for (int i = 0; i < 1000 i++) {
str = "" + i;
}
System.out.println (str);
can use "+" or "+ +" operator stitching a large number of strings, in a large number of string concatenation operation, the direct addition of two string objects, will allocate memory for the newly created string, the original two string objects are not released, which consumes a lot of memory resources.
In our highly visited web site, some of the small problems may be magnified, which can seriously affect the performance of the system bottlenecks. correct usage
StringBuffer buf = new StringBuffer ();
for (int i = 0; i < 1000 i++) {
buf.append (""). Append (i);
}
String str = buf.tostring ();
System.out.println (str);
test the attention point
The growth of memory footprint through continuous stress testing