The StringBuffer class
The base.StringBuffer
class is a built-in class designed to manipulate
character strings.
This class is optimized for string operations such as scanning, replacements, concatenation.
Use the base.StringBuffer
class instead of STRING
variables to implement heavy-duty
string manipulations. When you use a base.StringBuffer
object, you work directly on
the internal string buffer. When you use the STRING
data type and modify a string,
the runtime system creates a new buffer. While this does not impact the performance of programs with
a user interface or even batch programs doing SQL, it can impact performance when you need to
rapidly process large character strings. For example, if you need to process 500 KB of text (such as
when you are performing a global search-and-replace of specific words), you get much better
performance with a base.StringBuffer
object than you would with a
STRING
variable.
When you pass a base.StringBuffer
object as a function parameter,
the function receives a variable that references the object. Passing the object by
reference is much more efficient than using a STRING
that is
passed by value, because STRING
data is copied on the stack. The
function manipulates the original string, not a copy of the string.