The difference between String, StringBuffer and StringBuilder of

StringBuffer, StringBuilder and String, as also used to represent strings. String class is immutable class, any change to the initiator generates a new String String object; the StringBuffer is a variable type, changes its meaning any string will not produce a new generation object. Since the variable and immutable have it all, why there is a StringBuilder it? I believe you early, during append, usually choose StringBuffer now!

Let me talk about the story of the collection, HashTable are thread-safe, many methods are synchronized method, and HashMap is not thread safe, but its performance in single-threaded programs is higher than HashTable. The difference between StringBuffer and StringBuilder class, too, and their principle of operation is basically the same, except that StringBufferd support concurrent operations, linear safe for multiple threads to use. StringBuilder does not support concurrent operations, linear unsafe, unsuitable for multi-threaded use. The newly introduced StringBuilder class is not thread safe, but its performance in single-threaded is higher than StringBuffer.

Original link: https: //blog.csdn.net/mad1989/article/details/26389541

Guess you like

Origin www.cnblogs.com/yingying7/p/12355906.html