my dog learned polymorphism
The moose likes Beginning Java and the fly likes String Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 32830
    
    4
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
    
    2

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: String
 
Similar Threads
StringBuffer question
Immutable classes
why string
StringBuffer and String returned from a method doubt
How is this possible if Strings are immutable?