What is the Main difference between String and
StringBuilder and why do we use StringBuilder.

Answer Posted / anandha kumar t

Both String and StringBuilder are classes used to
handle the strings.

The most common operation with a string is
concatenation. This activity has to be performed very
efficiently. When we use the "String" object to concatenate
two strings, the first string is combined to the other
string by creating a new copy in the memory as a string
object, and then the old string is deleted. This process is
a little long. Hence we say "Strings are immutable".

When we make use of the "StringBuilder" object, the
Append method is used. This means, an insertion is done on
the existing string. Operation on StringBuilder object is
faster than String operations, as the copy is done to the
same location. Usage of StringBuilder is more efficient in
case large amounts of string manipulations have to be performed.

Is This Answer Correct ?    81 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is jagged array in c#?

546


Can you use foreach iteration on arrays in c#?

600


What is object pool in .net?

526


Is c# good for beginners?

471


What basic steps are needed to display a simple report in crystal?

536






Which property do we set on a Combo Box to display data on it prior to setting the DataSource ?

534


What are the advantages of using c#?

505


Which technology is best for desktop application?

429


What does break do in loop?

490


What is master page in asp net c#?

472


What is property in c#?

536


What is Implementation inheritance and interface inheritance?

491


Is there an equivalent to the instanceof operator in visual j++?

515


What do u mean by thread safe?

495


Is java better than c sharp?

510