B
Bob Rivers
Hi,
I was searching comp.lang.java and I didn't found a "definitive"
answer about. Taking a looking into Java Glossaty, I found that:
"Strings are immutable. Therefore they can be reused indefinitely, and
they can be shared for many purposes. When you assign one String
variable to another, no copy is made. Even when you take a substring
there is no new String created. New Strings are created when: you
concatentate. you do reads...." (I didn't understand "you do reads".
Sorry my english).
Ok, there is no doubt that when I concatenate strings (+=) java will
generate a new object. But, if I only assign a new value to a String,
will a new String be created?
For example:
String str = "Hi";
str = "Hi Bob!";
In the example above, how many strings I created?
TIA,
Bob - Brazil
I was searching comp.lang.java and I didn't found a "definitive"
answer about. Taking a looking into Java Glossaty, I found that:
"Strings are immutable. Therefore they can be reused indefinitely, and
they can be shared for many purposes. When you assign one String
variable to another, no copy is made. Even when you take a substring
there is no new String created. New Strings are created when: you
concatentate. you do reads...." (I didn't understand "you do reads".
Sorry my english).
Ok, there is no doubt that when I concatenate strings (+=) java will
generate a new object. But, if I only assign a new value to a String,
will a new String be created?
For example:
String str = "Hi";
str = "Hi Bob!";
In the example above, how many strings I created?
TIA,
Bob - Brazil