Answers for "heap memory vs stack memory vs string pool memory"

4

heap memory vs string 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
4

heap memory vs string 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