| Author |
String
|
shruti patel
Ranch Hand
Joined: Mar 10, 2008
Posts: 52
|
|
string is immutable? right every one knows that, my question is it advantage or disadvantage making string immutable?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
|
There is discussion of a similar subject in this recent thread.
|
 |
Arijit Daripa
Ranch Hand
Joined: Aug 09, 2008
Posts: 142
|
|
Originally posted by shruti patel: string is immutable? right every one knows that, my question is it advantage or disadvantage making string immutable?
One of the advantages Immutable objects behave like primitive datatypes a bit. Like.... So we can use String objects as we use the primitives, except some cases like argument passing etc One of the Disadvantages Whenever their(immutable objects') contents are tried to be changed, new objects are created and their references are assigned to the reference variable. Hence older objects are thrown floating in the HEAP,reducing usable memory size. I am giving the keyboard a rest here, because it takes a long to disscuss it in depth. Follow Kathy Sierra & Bert Bates. It will help you the best.
|
SCJP 5
|
 |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2561
|
|
|
And Shruti please make your subject more descriptive, so that readers get what you question is related to. Please read this for more information.
|
SCJP, SCWCD.
|Asking Good Questions|
|
 |
 |
|
|
subject: String
|
|
|