The difference between StringBuffer and StringBuilder in Java
When I used java earlier, I knew that there was a class called StringBuffer, which was used to splice long strings. After turning to c#, there is also a class like function called StringBuilder, which is abbreviated as sb, which is very easy to remember.
Later, when I transferred back to Java, I found that Java also had StringBuilder, so I wondered why StringBuilder was launched after StringBuffer.
The original Java StringBuilder (like c#) is non thread safe, while the previous StringBuffer has certain thread safe properties. Of course, StringBuilder is introduced mainly because it is not necessary to use it in the case of multithreading.
The common use cases of StringBuilder (or StringBuffer) are:
In this case, StringBuilder is not a class member, it is just a local variable, and there is no multithreading problem at all.
Therefore, the introduction of StringBuilder has brought great performance improvement, and there is no security problem at all