Wednesday, 29 March 2017

If Strings are immutable then what the other way to work on "strings"?


So we have studied that Strings are immutable so we have got StringBuffer class which represents strings in such a way that we can manipulate data in it(I am talking about Object).

Creating a StringBuffer reference object is same like creating any new Object of any class.

Example:
StringBuffer stringBuf = new StringBuffer("abc");

or 

StringBuffer stringBuf = new StringBuffer();
stringBuf.append("abc");

Explanation:
This will create an object "abc" in String Constant Pool,  and the reference variable will be stringBuf.

No comments:

Post a Comment