0

How does the String variables be saved in memory?

In C++, strings are saved with the number of characters that contains the string and the chatscters, for example: // C++ string name = "Paul"; This variable is saved like as: 3 | "Paul" Bot exactly but that is the idea. Java saves the strings like C++ does?

30th May 2017, 5:21 AM
Bill Gates
Bill Gates - avatar
1 Odpowiedź
+ 1
Thank you Google... https://www.quora.com/How-are-strings-stored-in-Javas-memory Every time you declare a String, a new instance of object String is created. This instance has 4 properties: - an array of chars - an int, representing its length - an int, representing the offset (?) - an int used to compute a hashcode When you declare a String by means of new String(...), it's stored into the heap memory. But if you declare it as String x = "...", it's created into the so said String constant pool. Sorry, I didn't find any official documentation that supports this explanation.
30th May 2017, 5:42 AM
Álvaro