+ 4

StringBuffer vs StringBuilder

I found that StringBuffer is synchronized while StringBuilder is not Here we talk about the synchronization of what exactly? Thanks in advance :)

21st Jan 2020, 4:14 PM
Hichem GOUIA
Hichem GOUIA - avatar
2 ответов
+ 9
Synchronization is suitable when you have multiple threads running concurrently. It prevents thread interference and by that I mean to say if a thread is synchronized then it has access to all the shared resources and let's a particular thread finish it's task. So the other threads have to wait for the resources to be freed for them to execute. So when we say that StringBuffer is synchronized then from my explanation above you can understand that it consumes more time and resource. But that makes it thread safe which is kind of an advantage.
21st Jan 2020, 4:35 PM
Avinesh
Avinesh - avatar
+ 2
Well explained 👍 thanks friend
21st Jan 2020, 5:26 PM
Hichem GOUIA
Hichem GOUIA - avatar