Java.lang.StringBuffer.append() Method



Description

The java.lang.StringBuffer.append(CharSequence s) method appends the specified CharSequence to this sequence.The characters of the CharSequence argument are appended, in order, increasing the length of this sequence by the length of the argument.

Declaration

Following is the declaration for java.lang.StringBuffer.append() method

public StringBuffer append(CharSequence s)

Parameters

s − This is the CharSequence to append.

Return Value

This method returns a reference to this object.

Exception

NA

Example

The following example shows the usage of java.lang.StringBuffer.append() method.

package com.tutorialspoint;

import java.lang.*;

public class StringBufferDemo {

   public static void main(String[] args) {

      StringBuffer buff = new StringBuffer("compile ");
      System.out.println("buffer = " + buff);

      CharSequence cSeq = "online";
      
      // appends the CharSequence
      buff.append(cSeq);

      // print the string buffer after appending
      System.out.println("After append = " + buff);
   }
}

Let us compile and run the above program, this will produce the following result −

buffer = compile
After append = compile online
java_lang_stringbuffer.htm
Advertisements