Answers for "string pool in java"

4

string pool in java

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