How to create a string, where single thread will be accessing and modifying that string?
Strings are immutable, so one can't modify it.
Since only one thread is going to access and modify your string, go for StringBuilder.
You can't use string as it is immutable.
It is not good to use StringBuffer because it has lot of locking and unlocking code for synchronization which will un necessarily take up CPU time. Don't use locks unless it is required.
In this scenario we don't need locks as we have only one thread, so go for StringBuilder.
Back To Top