Sunday, October 1, 2017

Difference Between String and StringBuilder


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.

No comments: