5

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.

Community
  • 1
  • 1
Anil Kumar C
  • 1,604
  • 4
  • 22
  • 43

1 Answers1

1

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