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

前端 未结 6 729
盖世英雄少女心
盖世英雄少女心 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:43

    I believe in the first case the compiler will be clever and put the concatenated string in the pool (i.e. you'll have only 1 string there)

提交回复
热议问题