what happens with new String(“”) in String Constant pool

前端 未结 5 1874
南方客
南方客 2021-01-24 07:05

if i create a string object as

String s=new String(\"Stackoverflow\");

will String object created only in heap, or it also makes a copy in Str

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-24 08:11

    A regular java object will be created in the heap, and will have a reference s type of String. And, there will be String literal in String Constant Pool. Both are two different things.

提交回复
热议问题