0 votes
1 view
in Java by (1.4k points)

What is the difference between these two following statements?

String s = "text";

String s = new String("text");

1 Answer

0 votes
by (13.2k points)

String s = new String("text");

It will create a new string object explicitly. Hence, its compilation is slower than the other.

String s = "text";

It creates a string literal from the string constant pool, if available. It will be stored in Heap Space. For code optimization and better performance, use this one.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...