Features:
-
Encapsulates the char [] array;
-
Is variable sequence of characters;
-
It provides a set of methods to modify the contents of the character;
-
Common append () instead of a string are connected to the string;
-
The default initial capacity internal character array is 16: super (str.length () + 16);
-
If more than 16 attempts to expansion, new array size becomes twice the original +2, if capacity is not enough, the expansion of capacity directly to the desired size. newCapacity = int
value.length * 2 + 2;
the difference:
1, on the thread safety:
- StringBuffer an older version of the provision, thread-safe. @since JDK1.0
- StringBuilder is generated after jdk1.5, thread-safe. @since 1.5
2, in the implementation of efficiency:
- List itemStringBuilder > StringBuffer > String
3, the source reflects:
- It is essentially calling the parent class abstract class AbstractStringBuilder to work, but the Buffer synchronization code plus the keyword so that the program can guarantee thread-safety issues.