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

Answers were Sorted based on User's Feedback



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

Answer / dinesh sharma

String bulider Can Be Used When More Than One String Can we
concatenated.
StringBuilder which is more efficient because it does
contain a mutable string buffer. .NET Strings are immutable
which is the reason why a new string object is created
every time we alter it (insert, append, remove, etc.).

StringBulider Is more Effiecent Then String B'Cuse It
Provide Some Standered Function like Append,Reverse,Remove
etc.

Is This Answer Correct ?    179 Yes 24 No

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

Answer / sandeep soni

String are Immutable (Not Modifiable). If you try to modify
the string it actually creates a new string and the old
string will be then ready for garbage collection.

StringBuilder when instantiated, creates a new string with
predefined capacity and upto that capacity it can
accodomate string without needing to create a new memory
location for the string....i mean it is modifiable and can
also grow as and when needed.

When the string needs to be modified frequently, preferably
use StringBuilder as its optimized for such situations.

Is This Answer Correct ?    113 Yes 11 No

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

Answer / 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

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

Answer / tharaknlr

Strings are immutable means Data value maynot be Changed and
Variable value may be changed.
StringBuilder performs is faster than Strings. and also
designed for Mutable Strings
we can use like this
System.text.StringBuilder

Is This Answer Correct ?    89 Yes 25 No

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

Answer / shaveen kaushal

Difference..
String..
1.Its a class used to handle strings.
2.Here concatenation is used to combine two strings.
3.String object is used to concatenate two strings.
4.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
5.we say "Strings are immutable".

String Builder..
1.This is also the class used to handle strings.
2.Here Append method is used.
3.Here, Stringbuilder object is used.
4.Insertion is done on the existing string.
5.Usage of StringBuilder is more efficient in case large
amounts of string manipulations have to be performed

Regards
Sridhar R
Nothing is illegal, Until You Get Caught

Is This Answer Correct ?    39 Yes 7 No

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

Answer / vijay rana

String class is immutable, means we can not change the
contents of string at run time,
for example
String s1="loin";
string s2=s1.insert(3,"g");
now s2 have the value login ,but one thing to notice here is
that we are not assigning this value into s1, because it is
not possible in String class
,but if we want to change the contents of s1 then we will
have to take the StringBuilder calss
because with the help of this class we can change the
contents of same string
examlpe:
String s1="loin";
s1=s1.insert(3,"g");
now s1 is "login"
here we are assigning the value again in s1,
this is the main difference between in string and
stringBuilder class

Is This Answer Correct ?    43 Yes 27 No

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

Answer / mahesh

String and StringBuilder Both are classe for store the
strings.
String Builder is faster than String. String is immitable,
StringBuilder is mutable.

Is This Answer Correct ?    28 Yes 14 No

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

Answer / ankur prasad gupta

Difference..
String..
1.Its a class used to handle strings.
2.Here concatenation is used to combine two strings.
3.String object is used to concatenate two strings.
4.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
5.we say "Strings are immutable".

String Builder..
1.This is also the class used to handle strings.
2.Here Append method is used.
3.Here, Stringbuilder object is used.
4.Insertion is done on the existing string.
5.Usage of StringBuilder is more efficient in case large amounts of string manipulations have to be performed

Is This Answer Correct ?    19 Yes 6 No

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

Answer / ashwini choudhari

string class u can't directly the change the string value
and u want to do some manipulation with the string object
then it's give the new memory in stack when u can the do
the manipulation with the string object but in String
Builder class not happened to give the new memory
allocation in stack it just repalcing the some part of
string which u want repalce or appended so that the
performances increases.
Actually String Builder it is referneces type .

Is This Answer Correct ?    11 Yes 8 No

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

Answer / swati

In stringBuilder we can modify original value
example: suppose a string "Swti" in that string we add a
after charator w then we can easily add the char a after w
then new string is "Swati"

But in string we can't modify original value we add add
another value in original value use concate function.
example: suppose a string is "Swati" in that string we
concate another string means "Pandey" by using concate
function

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More C Sharp Interview Questions

How can we give strong name to assembly? What is satellite assembly?

2 Answers   SMNetserv,


What do u mean by delegation?

0 Answers  


What you mean by inner exception in c#?

0 Answers  


boxing means converting value type to reference type and unboxing means converting reference type to value type.why we need boxing and unboxing?

3 Answers   General Mills, Value Labs,


how to retrieve binary data from database (using c#.net and sql server/windows application)

2 Answers   Soltius,






What is the difference between serialization and deserialization in c#?

0 Answers  


What is manifest ?

3 Answers   Digital GlobalSoft,


what is the syntax to inherit from a class in c#?

0 Answers   Siebel Systems,


How more than one version of an assembly can keep in same place?

0 Answers  


Why is xml called extensible?

0 Answers  


Different between method overriding and method overloading?

0 Answers  


What is array and types of array in c#?

0 Answers  


Categories