Java String Constant Pool - Number of Objects Created

前端 未结 3 1769
挽巷
挽巷 2021-01-19 19:05

How many string objects will be created by the following code?

String s = \"Mahendra\" + \"Singh\" + \"Dhoni\";

Will it create 4 string obj

3条回答
  •  后悔当初
    2021-01-19 19:41

    This will create only 1 string s in string pool. Please read the difference bwt String object and literal it will help you understand.

提交回复
热议问题