Solved

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

Posted on 2006-11-12
5
193 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now