Home » Java programming language

Java StringBuffer append(String s) method with Example

Java StringBuffer append(String s) method: Here, we are going to learn about the append(String s) method of StringBuffer class with its syntax and example.
Submitted by Preeti Jain, on June 29, 2019

StringBuffer Class append(String s)

  • This method is available in package java.lang.StringBuffer.append(String s).
  • This method is used to append the specified object with the given object.
  • This method is overridable so it is available in different forms like append(String s) or append(Boolean b) or append(int i) or append(char c) etc.

Syntax:

    StringBuffer append(String s){
    }

Parameter(s):

The return type of this method is StringBuffer that means this method returns a reference to this object.

Return value:

We can pass only one object as a parameter in the method and that object will append in a sequence and object can be of any type.

Java program to demonstrate example of append(String s) method

import java.lang.StringBuffer;

public class Main {
    public static void main(String[] args) {

        StringBuffer sb = new StringBuffer("Java");

        // use append(Boolean b) it will append the Boolean 
        // parameter as string to the StringBuffer

        sb.append(true);

        // Display result after appending

        System.out.println("The result will be after appending Boolean object to the StringBuffer is: "+sb);

        sb = new StringBuffer("Version");

        // use append(int i) it will append the Integer parameter 
        // as string to the StringBuffer

        sb.append(8);

        // Display result after appending

        System.out.println("The result will be after appending Integer object to the StringBuffer is: "+sb);
    }
}

Output

D:\Programs>javac Main.java

D:\Programs>java StringBufferClass
The result will be after appending Boolean object to the StringBuffer is :Javatrue
The result will be after appending Integer object to the StringBuffer is :Version8





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.