new String overriding the previous String

Ok, I want to ask whether this code fragment memory efficient or not:

String str =new String("The first value");

...//some code here

str =new String("The second value");

I mean what happens to the memory? Is it properly released from the first object?

And if I do this hundred of times wil it be ok?

[485 byte] By [prnga] at [2007-11-27 6:41:01]
# 1

It's more efficient if you change it to:

String str = "The first value";

...//some code here

str = "The second value";

There's no need for the String constructor having a String parameter. Now both String constants reside in the constant pool, so it's pretty efficient.

quittea at 2007-7-12 18:10:28 > top of Java-index,Java Essentials,Java Programming...
# 2
Ok, thanks for reply.Is it called autoboxing(when you initialize object with not an object)?
prnga at 2007-7-12 18:10:28 > top of Java-index,Java Essentials,Java Programming...
# 3
Not in the case of String, this is just a special treatment for a often-used type which otherwise would be hard to be represented in a primitive form.
quittea at 2007-7-12 18:10:28 > top of Java-index,Java Essentials,Java Programming...