StringBuffer Class Properties and Methods

This section describes the StringBuffer class, it properties and methods.

java.lang.StringBuffer: A class represents a mutable sequence of characters stored in an internal buffer. An instance of StringBuffer has 3 important properties:

The sequence of characters in the buffer can be manipulated by the following methods:

The capacity, size of the buffer, may be affected by the following methods:

Is there any method that could cause the capacity to be decreased? I don't see any.

Many methods in StringBuffer class return current object. This allows us to write multiple method calls in one statement like this:

   s = s.append("It's ").append{10).append(" o'clock.");

Based on the J2SDK API Specification, an instance of StringBuffer is used by the Sun Java compiler to implement the string concatenation operations. For example, the following statement:

   s = "It's " + 10 + " o'clock.";

will be compiled as:

   s = new StringBuffer().append("It's ").append(10)
      .append(" o'clock.").toString();

Last update: 2014.

Table of Contents

 About This Book

 Installing JDK 1.8 on Windows

 Execution Process, Entry Point, Input and Output

 Primitive Data Types and Literals

 Bits, Bytes, Bitwise and Shift Operations

 Managing Bit Strings in Byte Arrays

 Reference Data Types and Variables

StringBuffer - The String Buffer Class

StringBuffer Class Properties and Methods

 SimpleStringBuffer - My Implementation of String Buffer

 Performance Comparison of String and StringBuffer

 System Properties and Runtime Object Methods

 Generic Classes and Parameterized Types

 Generic Methods and Type Inference

 Lambda Expressions and Method References

 Execution Threads and Multi-Threading Java Programs

 ThreadGroup Class and "system" ThreadGroup Tree

 Synchronization Technique and Synchronized Code Blocks

 Deadlock Condition Example Programs

 Garbage Collection and the gc() Method

 Outdated Tutorials


 PDF Printing Version