pcyuen98 / covidAngular

0 stars 0 forks source link

KT - Difference between String, StringBuilder, and StringBuffer #19

Open AdibahTalib opened 3 years ago

AdibahTalib commented 3 years ago
Factor String StringBuffer StringBuilder
Uses when its not going to change much when its going to change often with many thread involved when it going to change often with single thread
Modifiable Immutable Mutable Mutable
Thread Safe Yes Yes No
Synchronized Yes Yes No
Performance Slow Slower than StringBuilder but faster than String Faster than StringBuffer
Storage Area Constant String Pool Heap Heap

*mutable - can change the value of the object

*immutable - cannot change the value of the object

*heap - is created when the JVM is started and may increase or decrease in size as the application runs.

*string constant pool - a special memory location for string to reuse of string objects ( it does not create the same string object if there is already a string constant in the pool )