Know that if multiple strings are spliced, using stringbuilder.append will be much more efficient than str+= ""
Because you do not have to create string objects and array copies,
In jdk1.5, 3 methods were tested to clear the builder
Package Com.jb.efile.model;
Import java.io.IOException;
public class Test {private static long;
public static void Main (string[] args) throws IOException {StringBuilder builder = new StringBuilder ();
Time = System.currenttimemillis ();
for (int i=0;i<10000000;i++) {builder = new StringBuilder ();
Builder.append ("AA");
Builder.append ("BB");
Builder.append ("CC");
Builder.append ("DD");
Builder.append ("ee");
} System.out.println ("New Time Consuming:" + (System.currenttimemillis ()-time);
for (int i=0;i<10000000;i++) {builder.delete (0, Builder.length ());
Builder.append ("a");
Builder.append ("B");
Builder.append ("C");
Builder.append ("D");
Builder.append ("E");
} System.out.println ("Delete time consuming:" + (System.currenttimemillis ()-time);
for (int i=0;i<10000000;i++) {builder.setlength (0);
Builder.append ("1a");
Builder.append ("1b");
Builder.append ("1c");
Builder.append ("1d");
Builder.append ("1e"); } System.out.println ("Setlenth=0 time Consuming: "+ (System.currenttimemillis ()-time);"
}
}
Output:
New time consuming: 1146
Delete time consuming: 2268
setlenth=0 time consuming: 3371
So I test new efficiency will be high, but a lot of people on the Internet test said delete efficiency, I hope you copy the code to their own environment in the test under the parents