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();

Table of Contents

 About This Book

 JDK - Java Development Kit

 Execution Process, Entry Point, Input and Output

 Primitive Data Types and Literals

 Control Flow Statements

 Bits, Bytes, Bitwise and Shift Operations

 Managing Bit Strings in Byte Arrays

 Reference Data Types and Variables

 Enum Types and Enum Constants

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

 Java Modules - Java Package Aggregation

 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

 Assert Statements and -ea" Option

 Annotation Statements and Declarations

 Java Related Terminologies

 Archived Tutorials

 References

 Full Version in PDF/EPUB