Thursday, June 28, 2012

String Immutability - String Builder

First of all Immutable means - Once created cannot be changed and Mutable means liable to change. Strings are immutable. The best example to demonstrate this would be a string concatenation example. When concatenating a string, a new string object is created and the variable references to the newly created object and the previously created object will be sent for garbage collection. This scenario would be explained further using the following code snippets.


To avoid this situation of StringBuilder class can be used as follows,


2 comments:

  1. DID NOT KNOW HOW TO OVER COME IT ..CHEERS BUDDY !! :)

    ReplyDelete
  2. I know little bit about the strcat() method in string.h header. Don't understand this much, but surely will be helpful in the future :)

    ReplyDelete