• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String

 
shruti patel
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
string is immutable? right every one knows that, my
question is it advantage or disadvantage making string
immutable?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49382
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is discussion of a similar subject in this recent thread.
 
Arijit Daripa
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Shruti please make your subject more descriptive, so that readers get what you question is related to. Please read this for more information.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic