Does Referncing change
Hi All,
Say I have the following:
String a = "Hello"; so a is refer to a particular area in the memory that holds String class, rihgt?
Now whe I mak some change:
a=a.substring(0,3)+"p!"; Does a now refer to a new String class that holds the world "help" or it refers to the old one?
Thank u in advance
Eyal
[349 byte] By [
Eyal2007a] at [2007-11-27 4:01:26]

a is now referring to a different string. You can check:
String a = "Hello";
String b = a; //b and a refer to the same object
a=a.substring(0,3)+"p!";
System.out.println(a==b); //false
> Hi All,
>
> Say I have the following:
>
> String a = "Hello"; so a is refer to a particular
> area in the memory that holds String class, rihgt?
>
> Now whe I mak some change:
>
> a=a.substring(0,3)+"p!"; Does a now refer to a new
> String class that holds the world "help" or it refers
> to the old one?
>
> Thank u in advance
> Eyal
It refers to a new instance of the String class.
As an aside, the new instance may refer to the same char array as the first instance.