Answers for "string constant pool"

4

string constant pool

String uses a special memory location
to reuse of String objects called String Constant Pool.
String objects created without
the use of new keyword are stored in the
String Constant Pool part of the heap.
It doesn't create the same string object
if there is already string constant in the pool.


String str = new String("");
String str2 = "";

Str goes to heap memory
str2 goes to string pool location

They both immutable and they save in different 
memory location.
Posted by: Guest on December-05-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language