Are strings created with + concatenation stored in the string pool?

前端 未结 6 723
盖世英雄少女心
盖世英雄少女心 2020-12-09 06:16

For instance

 String s = \"Hello\" + \" World\";

I know there are two strings in the pool \"Hello\" and \"World\" but, does: \"Hello World\

6条回答
  •  暖寄归人
    2020-12-09 06:45

    If I am wrong please correct me. As per my understanding only one object is going to be created in SCP. As String s = "Hello" + " World"; is a compile time constant.So compiler will append these two strings at compile time only.And only one object will be created in SCP. If you open and see .class file you will find "HelloWorld in .class file

提交回复
热议问题