How is memory allocated for a string, say in Java or C++? This might be silly, so please excuse me. I'm wondering because a string is of unknown size.
In Java, String
is an immutable Object, so the "size" of the String
has to be known at time of allocation. It'll end up allocated in a shared object pool if it's "static" (e.g. a String
litteral, like "Hey, I'm a String litteral!"
), or on the heap if it's constructed using new String(...)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With