How many String objects will be created here?

java, string

Solution

There will be at least four objects:

- The interned string `"xyz"`

- The copy of the interned `"xyz"` string

- The interned string `"abc"`

- The result of concatenating the two strings.

Problem

``` String x = new String("xyz"); String y = "abc"; x = x + y; ``` How many `String` objects would get created in this code?

Original source