• Post Reply Bookmark Topic Watch Topic
  • New Topic

Strings and StringBuffer  RSS feed

 
Suhail Mohammed
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what makes strings immutable and StringBuffer mutable
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know what "immutable" means?

Class String does not have any methods that change the string itself. Once you have created a String object, the content of the String object cannot be changed. That's why String is immutable.

Class StringBuffer does have a lot of methods that change the internal state of the object. You can append text to a StringBuffer for example. That's why StringBuffer is not immutable.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!