This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Difference between mutable & immutable striing? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between mutable & immutable striing?" Watch "Difference between mutable & immutable striing?" New topic
Author

Difference between mutable & immutable striing?

sethuraman vanangamudi
Greenhorn

Joined: Dec 16, 2004
Posts: 1
I am new in java.I attended one interview last week.the interviewer asked this question.
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
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


SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
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 ]

Mike Gershman
SCJP 1.4, SCWCD in process
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between mutable & immutable striing?