Java.lang.StringBuilder.append() Method

Advertisements


Description

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

Declaration

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

public StringBuilder append(Object obj)

Parameters

  • obj -- This is an object.

Return Value

This method returns a reference to this object.

Exception

  • NA

Example

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

package com.tutorialspoint;

import java.lang.*;

public class StringBuilderDemo {

  public static void main(String[] args) {
  
    StringBuilder str = new StringBuilder("Compile ");
    System.out.println("string = " + str);
       
    Object obVal = "Online";
    // appends the Object value
    str.append(obVal);
    
    // print the StringBuilder after appending
    System.out.println("After append = " + str);
  }      
}  

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

string = Compile
After append = Compile Online



Advertisements
Advertisements