Why are we using string

why are we doing operation on the string? Mam told in her previous lecture when introducing StringBuilder that while performing an operation on a string O(n) loop might behave as O(n2).

in recursion its preferred to use string because they are created in main stack.
you can also use stringbuilder in place of string but you have to take care of addition and removal of elements in stringbuilder

Will the time complexity be better in stringbuilder or when we are using string.
If the complexity will be same then please explain why.

@ubaidshaikh9999
yeah time complexity will be better in Stringbuilder because Strings in Java are immutable, so the concatenation operator has to generate a new, slightly longer string for each stack frame.So creating a new string at each stack frame will take more time.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.