StringBuilder and StringBuffer in java

Sting java in splicing with a plus sign, from java5 start, plus the use of an outer loop is optimized for use in an internal StringBuilder append a string concatenation method. Using a plus sign in the string loop is each time a new StringBuilder reduce efficiency. The best approach is to create a StringBuilder object outside the loop, the inner loop then append to the string concatenation.

StringBuilder speed is faster than StringBuffer, although two of them inherit from the same abstract class, basically methods are the same, to achieve basically the same, but almost all of the StringBuffer methods are synchronized so coupled with low efficiency.

Published 15 original articles · won praise 0 · Views 1076

Guess you like

Origin blog.csdn.net/ma316110/article/details/82109211