StringBuffer append()


append()

The append() method at the end of the concatenates StringBuffer object allows any other type of data string representation. There are several overloaded versions. Here are some of the forms:

StringBuffer append(String str)
StringBuffer append(int num)
StringBuffer append(Object obj)

A string representation of each parameter is obtained, often by calling String.valueOf(). The result is attached to the current StringBuffer object. The buffer itself returns by each append() of the append. This allows the following calls to be tied together, as shown in the following example:

Example

Program
public class Main 
{
  public static void main(String[] args) 
  {
    String s;
    int a = 40;
    StringBuffer sb = new StringBuffer(38);
    
    s = sb.append("a = ").append(a).append(".").toString();
    System.out.println(s);
  }
}