Java new String and new StringBuilder in heap behavior
Does the String pool reside on the heap? If yes, are String literals eligible for garbage collection? When using new String("abc") , we know that it creates an object on the heap and places the String literal in the String pool. So my 2nd question is: Does new StringBuilder("abc") behave the same way as new String("abc") ? If yes, how does StringBuilder manipulate the String literal inside the String pool? You are confusing compile time, load time, and runtime. A string literal is added to the constant pool at class loading time. Just a mention of a literal anywhere in the class code is enough