Interview Question
Qus: What is String Builder? Which one Preferable string or String Builder?
To avoid string replacing, appending, removing or inserting new strings in the initial string, StringBuilder was introduced. StringBuilder is a dynamic object. It doesn’t create a new object in the memory but dynamically expands the needed memory to accommodate the modified or new string.
StringBuilder is preferred since it performs faster than string in case we are modifying the string by appending string values.
Answers (2)
StringBuilder sb = new StringBuilder(“Hi Team!!”);
We can prefer StringBuilder. Beacuse it performs faster than string when appending multiple string values.
StringBuilder is preferred since it performs faster than string in case we are modifying the string by appending string values.