Solved

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

Posted on 2006-11-12
5
198 Views
Last Modified: 2013-12-29
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
Comment
Question by:letsbedecent
5 Comments
 
LVL 92

Accepted Solution

by:
objects earned 84 total points
ID: 17928175
Basically becuase String's are immutable objects
0
 
LVL 6

Assisted Solution

by:valipotor
valipotor earned 83 total points
ID: 17928396
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
 
LVL 5

Assisted Solution

by:kannan_ekanath
kannan_ekanath earned 83 total points
ID: 17929420
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 84
mockito example issue 8 72
String array comparison 4 32
JAVA API design with micro service cloud in mind 1 13
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question