Counting String objects created by Java code

前端 未结 13 1736
失恋的感觉
失恋的感觉 2020-12-05 14:04

How many String objects are created by the following code?

String x = new String(\"xyz\");
String y = \"abc\";
x = x + y;

I have visited ma

13条回答
  •  囚心锁ツ
    2020-12-05 14:39

    The answer is 4

    String x = new String("xyz");//First Object
    
    String y = "abc";//Second Object
    
    x = x + y;//Third, fourth Object
    

提交回复
热议问题