The difference between String, StringBuffer, StringBulider of

1, thread safety:

Thread safety: String, StringBuffer

Thread safe: StringBulider

2, efficiency

StringBulider fastest, Stringbuffer followed, String worst

3, storage space

String objects can not be changed once created, is a constant, after String operations will generate a new String object, inefficient and a waste of space.

StringBuffer and StringBulider objects can all be changed, saving space, high efficiency. You can not use String "+" but the use of stitching to avoid a large number of intermediate objects useless, space-consuming and inefficient executed (newly created object, the object takes much time recovery).

4, usage scenarios

A small amount of data: String

Large amounts of data, multi-threading: StringBuffer

Large amounts of data, single-threaded: StringBulider

Guess you like

Origin www.cnblogs.com/zhai1997/p/11348922.html