“Разница между StringBuffer и StringBuilder” Ответ

Разница между StringBuffer и StringBuilder

StringBuffer:
1. StringBuffer class is synchronized
2. It is thread-safe
3. It is slower than StringBuilder

StringBuilder:
1. StringBuilder class is not synchronized
2. It is not thread-safe
3. It is faster than StringBuffer
Tiny Coders

String vs StringBuilder против StringBuffer

If a string is going to remain constant throughout the program, 
then use the String class object because a String object is immutable.
If a string can change (for example: lots of logic and operations in the construction of the string) 
and will only be accessed from a single thread, using a StringBuilder is good enough.
If a string can change and will be accessed from multiple threads, 
use a StringBuffer because StringBuffer is synchronous, 
so you have thread-safety.
If you don’t want thread-safety than you can also go with StringBuilder class as it is not synchronized.
Preeti Sekhon

Ответы похожие на “Разница между StringBuffer и StringBuilder”

Вопросы похожие на “Разница между StringBuffer и StringBuilder”

Больше похожих ответов на “Разница между StringBuffer и StringBuilder” по Java

Смотреть популярные ответы по языку

Смотреть другие языки программирования