質問

If there are two strings string1 and string2 contained in string pool referenced to String literals, will System.out.println(string1 + string2) generate additional string object in String pool as string3=string1+string2;? If not, why?

Like to add for more clarity how many objects are allocated in pool in such case?

正しい解決策はありません

他のヒント

The expression

"string1" + "string2"

will result in a string constant

"string1string2"

created at compile time and added to the enclosing class's constant pool.

The expression

string1 + string2

where string1 and string2 are arbitrary String-typed variables will compile into executable code which concatenates two strings. The result is not committed to the pool.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top