1. Performance comparison:StringBuilder > StringBuffer > String
2. String < (stringbuffer,stringbuilder) the cause
String: Strings constant
StringBuffer: String variable
StringBuilder: String variable
3. Source Code Analysis
String: Look at the source, the declaration of the string class is: Public final, so it is clear that the final value is not changed, so if we use string to manipulate strings, once the value of the string is changed, Creates a new space in memory to hold the new string, so it is inefficient. So, generally involved in string manipulation, we generally use StringBuffer or StringBuilder.
StringBuffer and StringBuilder both integrate Abstractstringbuilder, and StringBuffer most methods are synchronized, which is thread-safe, And StringBuilder is not, so, we look at the API can know, StringBuilder can operate stringbuffer, but StringBuffer can not operate StringBuilder, which is the cause of the thread. Therefore, it is conceivable that the efficiency of stringbuffer is certainly not StringBuilder, because stringbuffer to maintain a synchronous lock, which is sure to consume some resources.
String, StringBuffer and StringBuilder differences and performance analysis