What is the Main difference between String and
StringBuilder and why do we use StringBuilder.
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
How many dimensions can an array have?
How do I start a program in c#?
What is the raise event used for?
Is stringbuilder faster than string concatenation c#?
What is the use of return in c#?
What does dbml mean in texting?
Is it possible to nest cfml conditional tags?
Integer at long type variable are not object.Support your answer with example.And explain the technique to convert from value type to reference type and vice-versa.
To catch any possible exception What is the C# syntax written ?
List the different stages of a thread?
What is c-sharp (c#)?
Why we use methods in c#?