• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between mutable & immutable striing?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new in java.I attended one interview last week.the interviewer asked this question.
 
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic