- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does the StringBuffer append() method do 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 basic syntax for append() method is as follows −
public StringBuffer append(data_type variable_name)
A program to illustrate the use of append() method is given as follows −
Example
import java.lang.*; public class Example { public static void main(String[] args) { StringBuffer s1 = new StringBuffer("The sun rises in the east "); System.out.println("Statement : " + s1); s1.append(true); System.out.println("Outcome : " + s1+"
"); StringBuffer s2 = new StringBuffer("Hello "); System.out.println("Statement : " + s2); s2.append("World"); System.out.println("Output: " + s2+"
"); char c = 'A'; StringBuffer s3 = new StringBuffer("Apple starts with "); System.out.println("Statement : " + s3); s3.append(c); System.out.println("Output : " + s3); } }
Output
Statement : The sun rises in the east Outcome : The sun rises in the east true Statement : Hello Output: Hello World Statement : Apple starts with Output : Apple starts with A
- Related Articles
- Call append() method to construct a StringBuffer object in Java
- What does the method clear() do in java?
- What does the method clone() do in java?
- What does the method firstElement() do in java?
- What does the method lastElement() do in java?
- What does the method removeAllElements() do in java?
- What does the method size() do in java?
- What does the method isEmpty() do in java?
- What does the method elements() do in java?
- What does the method toArray() do in java?
- What does the method pop() do in java?
- What does the method peek() do in java?
- What does the method empty() do in java?
- What does the method trimToSize() do in java?
- What does the method getFirst() do in java?

Advertisements