Java StringBuilder append() method

append(String str): append the specified string at the end of this string.

Syntax:

public StringBuilder append(String str)

 

Note: if the specified string is null then it appends a “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.

 

StringBuilder append() Example

class TestStringBuilder{
    StringBuilder sb = new StringBuilder("Hello ");

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

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

Output

Hello www.w3schools.blog

 

Please follow and like us:
Content Protection by DMCA.com