aspose file tools*
The moose likes Beginning Java and the fly likes String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String" Watch "String" New topic
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: 40052
    
  28
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: 2718
    
    6

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|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String