Search This Blog

Java :Question with Answer

You say that once created, String objects are immutable. I understand that, from a
practical point of view, this is not a serious restriction, but what if I want to create a string that can be changed?

You’re in luck. Java offers a class called StringBuffer, which creates string objects
that can be changed. For example, in addition to the charAt( ) method, which obtains
the character at a specific location, StringBuffer defines setCharAt( ), which sets a
character within the string. However, for most purposes you will want to use String,
not StringBuffer.