
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Call append Method to Construct a StringBuffer Object in Java
The StringBuffer append() method appends the String representation of the particular argument to the sequence. It is a method of the java.lang.StringBuffer class. This method returns a reference to the object.
The method changes the value of the object called in the method. Each primitive data type will have a separate method −
public StringBuffer append(double d) public StringBuffer append(float f) public StringBuffer append(int i) public StringBuffer append(String str) public StringBuffer append(long l) public StringBuffer append(char[] str) public StringBuffer append(char[] str, int offset, int len) public StringBuffer append(Object obj) public StringBuffer append(boolean b) public StringBuffer append(char c) public StringBuffer append(StringBuffer sb)
Example
A program to illustrate the use of append() method to construct a StringBuffer Object is given as follows −
import java.lang.*; public class Example { public static void main(String[] args) { StringBuffer s1 = new StringBuffer("Hello "); System.out.println("Statement : " + s1); s1.append("World"); System.out.println("Output: " + s1); } }
Output
Statement : Hello Output: Hello World
Advertisements