Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between mutable & immutable striing?

 
sethuraman vanangamudi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new in java.I attended one interview last week.the interviewer asked this question.
 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sethuraman,
According to my knowledge, in Java, all Strings are immutable, which means once you assign a value and then change it, what you get is a new string, not the same one. To over come this, there is a class called StringBuffer, where you can change the value. Hope this helps you. Good luck and Welcome to Java
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some kinds of Java objects cannot be modified once they are created. That makes them immutable. If you think you are changing a String, you are really creating a new String.

However, there are StringBuffer objects that also hold a series of caracters and can be changed. That makes them mutable.
[ December 16, 2004: Message edited by: Mike Gershman ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic