StringBuffer class enables you to represent and manipulate sequence of characters. Unlike String class, StringBuffer class is mutable. That is, you can change the contents of a StringBuffer object. When you modify a string of StringBuffer class, you are 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. The instances of StringBuffer hold the sequence of characters in some internal array of characters. The StringBuffer has a capacity which is the number of characters it can hold without requiring reallocation. When the length of characters in the StringBuffer overflow and exceed the capacity, the capacity is automatically increased. The following are the constructors of StringBuffer class:
// To create an empty StringBuffer with a default initial capacity of 16 characters StringBufferBasics CODE class StringBufferBasics OUTPUT Merit*Campus DESCRIPTION In the above program, we initially created an instance of the THINGS TO TRY
|