Java StringBuffer append() Method

append(String str)

append the specified string at the end of this string.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public synchronized StringBuffer append(String str)
public synchronized StringBuffer append(String str)
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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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();
}
}
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(); } }
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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Hello www.w3schools.blog
Hello www.w3schools.blog
Hello www.w3schools.blog