Main Page | See live article | Alphabetical index

StringBuffer

In computer programming, the StringBuffer class is one of two core string classes in Java. Most of the time, the String class is used. The point of this class is it is a mutable object while String is immutable (see immutable object). That means the content of StringBuffer objects can be modifed while every methods of string class returns a new string and result in improving runtime efficiency. For example, following code uses StringBuffer instead of String for performance improvement.
Reader reader = new FileReader ("file");
char buf[] = new char[10240];
StringBuffer sbuf = new StringBuffer ();
while (reader.ready ()) {
	sbuf.append (buf, 0, reader.read (buf));
}