Java has also a class that is very similar to String but whose instances are mutable objects: the class StringBuffer.
Specifically, the class StringBuffer has methods to modify the string represented by an object .
StringBuffer()
Constructs a string buffer with no characters in it and an initial capacity of 16 characters. |
StringBuffer(String str)
Constructs a string buffer so that it represents the same sequence of characters as the string argument; in other words, the initial contents of the string buffer is a copy of the argument string. |
StringBuffer |
append(String str)
Appends the string to this string buffer. |
StringBuffer |
insert(int offset,
String str)
Inserts the string into this string buffer. |
StringBuffer |
replace(int start,
int end,
String str)
Replaces the characters in a substring of this StringBuffer
with characters in the specified String . |
String |
toString()
Converts to a string representing the data in this string buffer. |