This is a very basic question. The extent of the answer i know to it is that Strings are immutable. Stringbuilders are not, so you can append characters at the end.
So how are stringbuilders internally organized??
String is an array of characters.
Is StringBuilder an array of characters too?
So, I have a StringBuilder MY_OBJ= “Hello”.
Now if i try to append characters to the end of MY_OBJ, does it not mean that you are actually creating a new array object and copying all these chars into a new one? If so how is it more efficient than a string?
And another question I have in mind is, how does one mark the end of a StringBuilder?
Like in C, we use a “/0”
I dunno. Let’s go see:
===
Apparently, in this particular implementation.
Not necessarily. The array isn’t necessarily full (
count < value.length), so a new array may not need to be allocated. Ideally, you initialized StringBuilder a capacity so that large enough array was allocated from the start.You don’t care –
String/StringBuilderwill handle it internally.