string - Why does java have StringBuilder or StringBuffer? -


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?

  1. 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

  2. now 1 need frequent string operation here comes stringbuffer thread safe (synchronized).

  3. 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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -