O'Reilly logo

Special Edition Using Java 2 Standard Edition by Geoff Friesen, Chuck Cavaness, Brian Keeton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the StringBuffer Class

The StringBuffer class enables you to create String objects that can be changed in various ways, unlike the String class, which are immutable. When you modify a string of the StringBuffer class, you're not creating a new String object, but rather operating directly on the original string itself. For this reason, the StringBuffer class offers a different set of methods than the String class, all of which operate directly on the buffer that contains the string.

Creating a StringBuffer Object

The StringBuffer class offers several constructors that enable you to construct a StringBuffer object in various ways. Those constructors look like this:

StringBuffer()
StringBuffer(int length)
StringBuffer(String str)

These constructors ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required