Java.lang.StringBuffer.append() Method

Advertisements


Description

The java.lang.StringBuffer.append(Object obj) method appends the string representation of the Object argument.

Declaration

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

public StringBuffer append(Object obj)

Parameters

  • obj -- This is the value of an object.

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("tutorials ");
    System.out.println("buffer = " + buff);
       
    Object obVal = "point";
    // appends the Object value
    buff.append(obVal);
    
    // 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 = tutorials
After append = tutorials point



Advertisements
Advertisements