And to abound in the same mould as in Raj's comment, the string object
"Sang" though still in memory is no longer addressable/referentiable and
could be candidate for the next garbage collection. Now the reference *name
* points only to "Shin"

On 31 August 2011 07:29, Raj Chauhan <rajkr.chau...@gmail.com> wrote:

> Yes, String is immutable. Each time when you assign different value to same
> string object, it is created a new object, not override the value. So as per
> your code below there are two object in memory.
>
>
> On Wed, Aug 31, 2011 at 12:37 AM, VM <veer.mucha...@gmail.com> wrote:
>
>> Why is String considered immutable while the code below works?
>>
>> String name = "Sang"; System.out.println(name);
>> name ="Shin";
>> System.out.println(name);
>>
>> --
>> To post to this group, send email to
>> javaprogrammingwithpassion@googlegroups.com
>> To unsubscribe from this group, send email to
>> javaprogrammingwithpassion+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/javaprogrammingwithpassion?hl=en
>
>
>  --
> To post to this group, send email to
> javaprogrammingwithpassion@googlegroups.com
> To unsubscribe from this group, send email to
> javaprogrammingwithpassion+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/javaprogrammingwithpassion?hl=en
>



-- 

Mes remerciements
Thanks

-- 
To post to this group, send email to javaprogrammingwithpassion@googlegroups.com
To unsubscribe from this group, send email to 
javaprogrammingwithpassion+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to