Java StringBuffer append() Method

append(String str)

append the specified string at the end of this string.

Syntax:

public synchronized StringBuffer append(String str)

 

Note: if the specified string is null then it appends the “null” string at the end.

If the append has an object, int, double, etc as an argument then the argument value is first converted into a string using String.valueOf()before appending.

 

Example

class TestStringBuffer{
    StringBuffer sb = new StringBuffer("Hello ");

    public void appendTest(){
        //concatenate the argument string 
                //at the end of this string.
        System.out.println(sb.append("www.w3schools.blog"));
    }
}

public class StringBufferAppendExample {
    public static void main(String args[]){
        //creating TestStringBuffer object
        TestStringBuffer obj = new TestStringBuffer();
        
        //method call
        obj.appendTest();
    }
}

Output

Hello www.w3schools.blog