Friday, January 22, 2010

Something about String and StringBuilder

1.string is immutable where is string builder is mutable
2.In stringBuilder, automatically increase and decrease size of string object whenever add elements and delete elements .Where in string , it is fixed size .
3.StringBuilder can perform a insert(),Delete(),Reverse(),Sort() operations etc and we can create multiple instances .Where as String , It  can't perform.
4.StringBuilder takes enough memory for variable .Where as String can't perform.

we use strings for non-changing strings because every time when a string is changed a new instance of string is created using new memory locations. whereas in stringbuilder we can work on the same memory location.
so stringbuilder is efficient in terms of memory for changing strings.

No comments:

Post a Comment