String, StringBuffer and StringBuilder difference?

String、StringBuffer、StringBuilder区别与联系

. 1 ) character sequences String class is immutable classes, i.e., once a String object is created, the sequence of characters contained in the object is not changed until the object is destroyed.
java.lang.String class is a reference data type, and a final type and therefore not inherit this class, the class can not be modified. In order to save space efficiency, we should use StringBuffer class
2 ) StringBuffer class represents a sequence of variable character string, the contents of which can be varied append, insert, reverse, setChartAt, setLength like. Once generated the final character string, which method calls into toString String
. 3 ) the JDK1.5 added a StringBuilder class, and StringBuffer similar, and a method of substantially the same configuration. Difference is that StringBuffer is thread-safe, but StringBuilder is not thread-safe, so performance is slightly higher. Typically, when you create a string variable content, priority should be given to use StringBuilder

Published 20 original articles · won praise 1 · views 616

Guess you like

Origin blog.csdn.net/qq_37206355/article/details/104984552