Visit our Youtube channel to access new animated learning tricks Click Here.
0 votes
2.5k views
by (7.8k points)

How can I remember about thread safety in StringBuilder and StringBuffer without getting confused with each other.

 

StringBuffer StringBuilder
Synchronized Non-Synchronized

 

1 Answer

0 votes
by (7.8k points)
Here is an easy trick to remember it.

Only StringBuilder has the letter 'i' in it . If you put the letter 'i' upside down, it becomes '!' - equivalent to 'not' symbol in programming languages.

Hence 'StringBuilder' can be related with the word 'not' which can help you remember -> non-synchronized.

"StringBu!lder"
Sharing improves retention
...