- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Java StringBuffer class.
The java.lang.StringBuffer class is a thread-safe, mutable sequence of characters. Following are the important points about StringBuffer −
- A string buffer is like a String but can be modified.
- It contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
- They are safe for use by multiple threads.
- Every string buffer has a capacity.
Example
import java.lang.*; public class StringBufferDemo { public static void main(String[] args) { StringBuffer buff = new StringBuffer("tuts "); System.out.println("buffer = " + buff); // appends the boolean argument as string to the string buffer buff.append(true); // print the string buffer after appending System.out.println("After append = " + buff); buff = new StringBuffer("abcd "); System.out.println("buffer = " + buff); // appends the boolean argument as string to the string buffer buff.append(false); // print the string buffer after appending System.out.println("After append = " + buff); } }
Output
buffer = tuts After append = tuts true buffer = abcd After append = abcd false
- Related Articles
- Constructors of StringBuffer class in Java.
- Methods of StringBuffer class in Java.
- Difference between String class and StringBuffer class in Java
- Difference Between String and StringBuffer Class in Java
- Is StringBuffer final in Java?
- Why StringBuffer is mutable in Java?
- Java String, StringBuffer and StringBuilder Tutorial.
- Java Program to Clear the StringBuffer
- Difference between StringBuilder and StringBuffer in Java
- Difference between string and StringBuffer in Java.
- Sorting collection of String and StringBuffer in Java
- Remove a character from a Java StringBuffer object
- Change a single character in a Java StringBuffer object in Java
- What is the use of StringBuffer class can anyone explain with an example?
- What does the StringBuffer append() method do in Java?

Advertisements