It is always customary to use string str = "..." When creating strings, and str = str+ "ABCD"; I have heard of Stringbuffer,stringbuilder, but I have never thought about it.
String at first glance is very convenient to create, in fact, when the string is more or the creation of multiple strings, there will be a big problem, because string in the new creation of the string is in the memory of a new memory to store this string, because string is static, The reason we look dynamic is because the JVM deceives us, and in memory there is a new object, so the speed of its operation is conceivable. But StringBuffer and StringBuilder are not the same.
StringBuffer and StringBuilder are dynamic, StringBuffer buffer= new StringBuffer ("StringBuffer"); Buffer.append ("ABCD"); The new StringBuffer object was not created during this process. So their reading and writing speed is basically 10 times or dozens of times times that of a string.
The difference between StringBuffer and stringbuild is that one thread-safe one is insecure, StringBuffer is thread-safe, and StringBuilder is thread insecure. Just like Hashtable and HashMap, they were used on different occasions. Stringbuffered use in multi-threading to ensure the security of synchronized data, StringBuilder use in a single thread to ensure the rapid reading and writing.
The Java Foundation String,stringbuilder,stringbuffer