• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

y wasn't the functionality of stringbuffer included in string itself ?

like doing
S + S + S + S + S + S + S
where S = string takes more time than the case where S = stringbuffer. Why wasnt the overloading of + for string itself made efficient ?
[Assuming thats the No.1 case for using stringbuffer - atleast I didnt use stringbuffer for any other purpose]
0
letsbedecent
Asked:
letsbedecent
3 Solutions
 
objectsCommented:
Basically becuase String's are immutable objects
0
 
valipotorCommented:
The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuffer class and its append method. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java. For additional information on string concatenation and conversion, see Gosling, Joy, and Steele, The Java Language Specification.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

valipotor
0
 
kannan_ekanathCommented:
If you wonder what an Immutable object is and why it enhances performance etc, kindly read these links,
http://www.javapractices.com/Topic29.cjp (Why you would need it)
http://en.wikipedia.org/wiki/Immutable_object (The definition)
http://www-128.ibm.com/developerworks/java/library/j-jtp02183.html (IBM article saying when you want to mutate)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now