0

The String objects are stored in heap. For example:

String s1 = new String("s1");

s1 object will be stored in heap;

The String literals are stored in string constant pool.

String s2 = "s2";

s2 object will be stored in string constant pool (possibly inside of heap).

I have heard about runtime constant pool.

But I do not understand what specifically will be stored there. Is it the same as string constant pool? Or what should I write so it stores in runtime constant pool?

Oleksandr Riznyk
  • 758
  • 1
  • 8
  • 19
  • check this https://stackoverflow.com/questions/4918399/where-does-javas-string-constant-pool-live-the-heap-or-the-stack – miskender Mar 03 '19 at 18:31
  • 1
    The string pool is largely a myth, a confusion of concepts, sometimes FUD spread by cargo culting seniors, who don’t know what they are talking about. From the programmer’s perspective, there’s nothing special about String, there’s no memory leak. In the newest Javas, the Strings actually live in the cheap. Check that answer above. – Mateusz Stefek Mar 03 '19 at 18:39

0 Answers0