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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Java,
Stringis an immutable Object, so the “size” of theStringhas to be known at time of allocation. It’ll end up allocated in a shared object pool if it’s “static” (e.g. aStringlitteral, like"Hey, I'm a String litteral!"), or on the heap if it’s constructed usingnew String(...).