Does Java new String () create a corresponding string constant in the string constant pool?

String str = new String("abc");

create a string in this way. Is there "abc" in the string constant pool?

Mar.28,2021

there will be "abc" in the constant pool, which can be disassembled. Create "abc" in the constant pool and new a String ("abc") in the heap. The str, will be saved in the stack and the address in the heap will be assigned to str


.

if abc, already exists in String str=new String ("abc"); the constant pool can be directly referenced using the ldc directive, if not created. To view constant pools, you can use the javap-v command

jclasslib

Menu