StringBuffer Handles variable strings. The String class creates a new object each time you change a string, while StringBuffer adds a string to the created object. That is, only one object is created.
StringBuilder Handles variable strings. It is a class released in JDK1.5, has the same method as StringBuffer, and the usage is the same as StringBuffer. The difference from StringBuffer is that it is "not thread-safe (not synchronized)". ** Fast processing because it is not synchronized **.
Processing speed is rarely required for training tasks, so I think you can use either one. I don't have to understand the meaning, so I think it's okay if I can answer quickly when asked the difference (because it's a newcomer: beginner :). If anything, I want you to be able to use StringBuffer / StringBuilder: star:
If you are refurbishing an existing program, you should use the one that is already heavily used. Even if it is NG in terms of manner, it is often better to follow the existing one, considering the maintainability after that. If you want to create a new one from scratch, use StringBuilder (personally) with an emphasis on speed.
Recommended Posts