Skip to main content
added 195 characters in body; added 631 characters in body
Source Link
rahul
  • 187.5k
  • 50
  • 239
  • 266

string is immutable and stringbuilder is mutable.

In object-oriented and functional programming, an immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created.

Immutable objects are often useful because some costly operations for copying and comparing can be omitted, simplifying the program code and speeding execution. However, making an object immutable is usually inappropriate if the object contains a large amount of changeable data. Because of this, many languages allow for both immutable and mutable objects.

Each time a concatenation is made to a string object a new string object is created with a new reference and it will be assigned to the object. The older object will still there be in memory.

string is immutable and stringbuilder is mutable.

string is immutable and stringbuilder is mutable.

In object-oriented and functional programming, an immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created.

Immutable objects are often useful because some costly operations for copying and comparing can be omitted, simplifying the program code and speeding execution. However, making an object immutable is usually inappropriate if the object contains a large amount of changeable data. Because of this, many languages allow for both immutable and mutable objects.

Each time a concatenation is made to a string object a new string object is created with a new reference and it will be assigned to the object. The older object will still there be in memory.

Source Link
rahul
  • 187.5k
  • 50
  • 239
  • 266

string is immutable and stringbuilder is mutable.