Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many string objects will be created by JVM version 1.6 [duplicate]

Tags:

java

Possible Duplicate:
Questions about Java's String pool

Recently I read a java article and found the following statement "improved the String pooling technology in java 6 onward". One of the example that they have mentioned as follows

String one = "one";
String two = new String("one");

Number of objects created by above example is = 1

Here I am little confused, even though we are using the new keyword how come it will not create a new object and uses the object created in the string pool.

Please clarify me.

like image 584
Anil Kumar C Avatar asked Nov 13 '22 05:11

Anil Kumar C


1 Answers

I think doing one == two should help determining how many objects got created.

like image 190
Mehul Lalan Avatar answered Nov 16 '22 02:11

Mehul Lalan