I think there are three differences between string and stringbuffer:
(1) What does string mean when we create a String object str1 = "ABC"? In this case, a space is opened to store ABC and str1 points to it, now I "re-assign" str1 = "def" to str1. In this case, a new space is created to store def, and str1 points to the new space. In this case, stringbuffer directly modifies the value in the starting space. Therefore, string is the changed address, while stringbuffer is the modified value.
(2) During the determination, the string object overwrites the equals () method of the object, compares the value rather than the address, while the stringbuffer does not override this method, and identifies the address.
(3) When connecting strings, stringbuffer is usually used, because it is more efficient, such as string a = new string ("hello"); A + = "world "; in fact, during the connection, A is converted into a stringbuffer object, and then connected to the world using the append method of stringbuffer, and finally converted to a string object.
The difference between stringbuffer and stringbuilder is that stringbuffer is thread-safe, while stringbuilder is insecure.