string - Why does java have StringBuilder or StringBuffer? -
this question has answer here:
there many differences between string
, (stringbuilder
or stringbuffer
) mutability , many string operations
may question seems bit silly, want know sake of programming paradigm.
i want ask, why has java implemented class, stringbuilder
or stringbuffer
data structure string
. why have not given features in string
itself.
why not make string
thread-safe or provide features stringbuilder
or stringbuffer
has?
string immutable , there many reason , benefit it. why? , necessity of it? (very popular topic ) search or read why-is-string-immutable-in-java or why-string-is-immutable-in-java
now 1 need frequent string operation here comes stringbuffer thread safe (synchronized).
- some 1 don't need thread safety here comes stringbuilder.
now 1 can still use stringbuffer when thread safety not necessary, slow. that's why both of them important.
string's differently handled jvm
if features of stringbuffer
added not immutable more.
update : point 2 , 3 altered comment of @jon skeet.
Comments
Post a Comment