Interviews3 answers
What are the differences between String and String Builder?
3 Answers
http://www.aspdotnet-suresh.com/2013/11/difference-between-string-and-stringbuilder-csharp.html
Munesh SharmaPosted May 30, 2016, 9:18 PM EDT
String
-----------
String is immutable. Immutable means once we create string object we cannot modify. Any operation like insert, replace or append happened to change string simply it will discard the old value and it will create new instance in memory to hold the new value.
Performance wise string is slow because every time it will create new instance
In string we don’t have append keyword
String Builder
----------------------
String builder is mutable it means once we create string builder object we can perform any operation like insert, replace or append without creating new instance for every time.
Performance wise stringbuilder is high because it will use same instance of object to perform any action
In StringBuilder we can use append keyword
Avikshith AradhyaPosted May 30, 2016, 2:53 AM EDT
String
String objects are immutable, which means that once they are created they cannot be changed. When we use one of the methods of the String class, we create a new string object.
Here concatenation is used to combine two strings.
String object is used 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
Less efficient
String Builder
StringBuilder are mutable class, which means when concatenate any text to the variable it allows us to modify the original value without creating a new object.
Here Append method is used.
Stringbuilder object is used.
Insertion is done on the existing string.
StringBuilder is more efficient for large amounts of string manipulations
Ajeet MishraPosted Sep 6, 2015, 10:38 PM EDT

